From owner-dev-commits-src-main@freebsd.org Wed May 5 21:13:03 2021 Return-Path: Delivered-To: dev-commits-src-main@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 DDCF5623976; Wed, 5 May 2021 21:13:03 +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 4Fb8Z75yMHz4l6R; Wed, 5 May 2021 21:13:03 +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 BF65D3E5F; Wed, 5 May 2021 21:13:03 +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 145LD3RG055196; Wed, 5 May 2021 21:13:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 145LD3eX055195; Wed, 5 May 2021 21:13:03 GMT (envelope-from git) Date: Wed, 5 May 2021 21:13:03 GMT Message-Id: <202105052113.145LD3eX055195@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 9a7c2de36460 - main - realloc: Fix KASAN(9) shadow map updates 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/main X-Git-Reftype: branch X-Git-Commit: 9a7c2de36460cdb916734a6969aac666707a639b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 21:13:03 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9a7c2de36460cdb916734a6969aac666707a639b commit 9a7c2de36460cdb916734a6969aac666707a639b Author: Mark Johnston AuthorDate: 2021-05-05 21:05:46 +0000 Commit: Mark Johnston CommitDate: 2021-05-05 21:12:51 +0000 realloc: Fix KASAN(9) shadow map updates When copying from the old buffer to the new buffer, we don't know the requested size of the old allocation, but only the size of the allocation provided by UMA. This value is "alloc". Because the copy may access bytes in the old allocation's red zone, we must mark the full allocation valid in the shadow map. Do so using the correct size. Reported by: kp Tested by: kp Sponsored by: The FreeBSD Foundation --- sys/kern/kern_malloc.c | 2 +- sys/vm/uma_core.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index e2a05c004637..75cbc2a0fd04 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1024,7 +1024,7 @@ realloc(void *addr, size_t size, struct malloc_type *mtp, int flags) * Copy over original contents. For KASAN, the redzone must be marked * valid before performing the copy. */ - kasan_mark(addr, size, size, 0); + kasan_mark(addr, alloc, alloc, 0); bcopy(addr, newaddr, min(size, alloc)); free(addr, mtp); return (newaddr); diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c index a85b88b24110..d2e01f3a0605 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -540,6 +540,9 @@ bucket_zone_drain(int domain) } #ifdef KASAN +_Static_assert(UMA_SMALLEST_UNIT % KASAN_SHADOW_SCALE == 0, + "Base UMA allocation size not a multiple of the KASAN scale factor"); + static void kasan_mark_item_valid(uma_zone_t zone, void *item) {