From nobody Mon Nov 01 14:32:58 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C9BB2182D5C0; Mon, 1 Nov 2021 14:32:58 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hjb9Q3KKVz3sDR; Mon, 1 Nov 2021 14:32:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 27606134A1; Mon, 1 Nov 2021 14:32:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A1EWwYr021292; Mon, 1 Nov 2021 14:32:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A1EWwg0021291; Mon, 1 Nov 2021 14:32:58 GMT (envelope-from git) Date: Mon, 1 Nov 2021 14:32:58 GMT Message-Id: <202111011432.1A1EWwg0021291@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 65f3c07b9899 - stable/13 - amd64: Add MD bits for KASAN List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 65f3c07b989942897fbc8991ad3887ab4e1440a2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=65f3c07b989942897fbc8991ad3887ab4e1440a2 commit 65f3c07b989942897fbc8991ad3887ab4e1440a2 Author: Mark Johnston AuthorDate: 2021-04-13 21:39:35 +0000 Commit: Mark Johnston CommitDate: 2021-11-01 14:02:41 +0000 amd64: Add MD bits for KASAN - Initialize KASAN before executing SYSINITs. - Add a GENERIC-KASAN kernel config, akin to GENERIC-KCSAN. - Increase the kernel stack size if KASAN is enabled. Some of the ASAN instrumentation increases stack usage and it's enough to trigger stack overflows in ZFS. - Mark the trapframe as valid in interrupt handlers if it is assigned to td_intr_frame. Otherwise, an interrupt in a function which creates a poisoned alloca region can trigger false positives. Sponsored by: The FreeBSD Foundation (cherry picked from commit f115c0612131d8f939f6f357f57bdd85bd6a59de) --- sys/amd64/amd64/machdep.c | 3 +++ sys/amd64/conf/GENERIC-KASAN | 7 +++++++ sys/amd64/include/param.h | 4 ++++ sys/x86/isa/atpic.c | 4 ++++ sys/x86/x86/local_apic.c | 7 +++++++ 5 files changed, 25 insertions(+) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 512fee0de7df..0e2e0e9db9e8 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1605,6 +1606,8 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) #endif thread0.td_critnest = 0; + kasan_init(); + TSEXIT(); /* Location of kernel stack for locore */ diff --git a/sys/amd64/conf/GENERIC-KASAN b/sys/amd64/conf/GENERIC-KASAN new file mode 100644 index 000000000000..8d5703141e86 --- /dev/null +++ b/sys/amd64/conf/GENERIC-KASAN @@ -0,0 +1,7 @@ +# $FreeBSD$ + +include GENERIC + +ident GENERIC-KASAN + +options KASAN diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h index 93ee524e1de2..cf1d2bd0a586 100644 --- a/sys/amd64/include/param.h +++ b/sys/amd64/include/param.h @@ -134,8 +134,12 @@ #define IOPERM_BITMAP_SIZE (IOPAGES * PAGE_SIZE + 1) #ifndef KSTACK_PAGES +#ifdef KASAN +#define KSTACK_PAGES 6 +#else #define KSTACK_PAGES 4 /* pages of kstack (with pcb) */ #endif +#endif #define KSTACK_GUARD_PAGES 1 /* pages of kstack guard; 0 disables */ /* diff --git a/sys/x86/isa/atpic.c b/sys/x86/isa/atpic.c index 07d63b041d0b..28c10ee7009f 100644 --- a/sys/x86/isa/atpic.c +++ b/sys/x86/isa/atpic.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -522,6 +523,9 @@ atpic_handle_intr(u_int vector, struct trapframe *frame) { struct intsrc *isrc; + /* The frame may have been written into a poisoned region. */ + kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0); + KASSERT(vector < NUM_ISA_IRQS, ("unknown int %u\n", vector)); isrc = &atintrs[vector].at_intsrc; diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c index ab19a6c7bc69..715ae7734e29 100644 --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -1299,6 +1300,9 @@ lapic_handle_intr(int vector, struct trapframe *frame) { struct intsrc *isrc; + /* The frame may have been written into a poisoned region. */ + kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0); + isrc = intr_lookup_source(apic_idt_to_irq(PCPU_GET(apic_id), vector)); intr_execute_handlers(isrc, frame); @@ -1314,6 +1318,9 @@ lapic_handle_timer(struct trapframe *frame) /* Send EOI first thing. */ lapic_eoi(); + /* The frame may have been written into a poisoned region. */ + kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0); + #if defined(SMP) && !defined(SCHED_ULE) /* * Don't do any accounting for the disabled HTT cores, since it