From owner-svn-src-stable-12@freebsd.org Wed May 6 17:12:27 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 376FE2DA585; Wed, 6 May 2020 17:12:27 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49HNSW04wfz3QsD; Wed, 6 May 2020 17:12:26 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E21D72C93; Wed, 6 May 2020 17:12:26 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 046HCQt3048689; Wed, 6 May 2020 17:12:26 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 046HCQkw048688; Wed, 6 May 2020 17:12:26 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <202005061712.046HCQkw048688@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Wed, 6 May 2020 17:12:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360693 - stable/12/sys/mips/mips X-SVN-Group: stable-12 X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: stable/12/sys/mips/mips X-SVN-Commit-Revision: 360693 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 May 2020 17:12:27 -0000 Author: brooks Date: Wed May 6 17:12:26 2020 New Revision: 360693 URL: https://svnweb.freebsd.org/changeset/base/360693 Log: MFC r359974: Don't directly access userspace memory. Rather then using the racy useracc() followed by direct access to userspace memory, perform a copyin() and use the result if it succeeds. Reviewed by: jhb Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D24410 Modified: stable/12/sys/mips/mips/trap.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/mips/mips/trap.c ============================================================================== --- stable/12/sys/mips/mips/trap.c Wed May 6 15:24:31 2020 (r360692) +++ stable/12/sys/mips/mips/trap.c Wed May 6 17:12:26 2020 (r360693) @@ -1404,7 +1404,7 @@ log_illegal_instruction(const char *msg, struct trapfr { pt_entry_t *ptep; pd_entry_t *pdep; - unsigned int *addr; + unsigned int *addr, instr[4]; struct thread *td; struct proc *p; register_t pc; @@ -1431,17 +1431,16 @@ log_illegal_instruction(const char *msg, struct trapfr * Dump a few words around faulting instruction, if the addres is * valid. */ - if (!(pc & 3) && - useracc((caddr_t)(intptr_t)pc, sizeof(int) * 4, VM_PROT_READ)) { + addr = (unsigned int *)(intptr_t)pc; + if ((pc & 3) == 0 && copyin(addr, instr, sizeof(instr)) == 0) { /* dump page table entry for faulting instruction */ log(LOG_ERR, "Page table info for pc address %#jx: pde = %p, pte = %#jx\n", (intmax_t)pc, (void *)(intptr_t)*pdep, (uintmax_t)(ptep ? *ptep : 0)); - addr = (unsigned int *)(intptr_t)pc; log(LOG_ERR, "Dumping 4 words starting at pc address %p: \n", addr); log(LOG_ERR, "%08x %08x %08x %08x\n", - addr[0], addr[1], addr[2], addr[3]); + instr[0], instr[1], instr[2], instr[3]); } else { log(LOG_ERR, "pc address %#jx is inaccessible, pde = %p, pte = %#jx\n", (intmax_t)pc, (void *)(intptr_t)*pdep, (uintmax_t)(ptep ? *ptep : 0)); @@ -1453,7 +1452,7 @@ log_bad_page_fault(char *msg, struct trapframe *frame, { pt_entry_t *ptep; pd_entry_t *pdep; - unsigned int *addr; + unsigned int *addr, instr[4]; struct thread *td; struct proc *p; char *read_or_write; @@ -1501,18 +1500,18 @@ log_bad_page_fault(char *msg, struct trapframe *frame, * Dump a few words around faulting instruction, if the addres is * valid. */ - if (!(pc & 3) && (pc != frame->badvaddr) && - (trap_type != T_BUS_ERR_IFETCH) && - useracc((caddr_t)(intptr_t)pc, sizeof(int) * 4, VM_PROT_READ)) { + addr = (unsigned int *)(intptr_t)pc; + if ((pc & 3) == 0 && pc != frame->badvaddr && + trap_type != T_BUS_ERR_IFETCH && + copyin((caddr_t)(intptr_t)pc, instr, sizeof(instr)) == 0) { /* dump page table entry for faulting instruction */ log(LOG_ERR, "Page table info for pc address %#jx: pde = %p, pte = %#jx\n", (intmax_t)pc, (void *)(intptr_t)*pdep, (uintmax_t)(ptep ? *ptep : 0)); - addr = (unsigned int *)(intptr_t)pc; log(LOG_ERR, "Dumping 4 words starting at pc address %p: \n", addr); log(LOG_ERR, "%08x %08x %08x %08x\n", - addr[0], addr[1], addr[2], addr[3]); + instr[0], instr[1], instr[2], instr[3]); } else { log(LOG_ERR, "pc address %#jx is inaccessible, pde = %p, pte = %#jx\n", (intmax_t)pc, (void *)(intptr_t)*pdep, (uintmax_t)(ptep ? *ptep : 0));