From nobody Thu Aug 01 20:35:33 2024 X-Original-To: dev-commits-src-all@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 4WZghQ0sm5z5RPsm; Thu, 01 Aug 2024 20:35:34 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZghP5XxWz4L3K; Thu, 1 Aug 2024 20:35:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722544533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2PcRil+nEEM3khN7Uvv17dW+kPToLeJ5ks627W6rfKk=; b=p8MTRc0D91OHCIG0WwuMtToLW4dPeOrW8ngXNubzn8aehYwE370oF8yh4XFqdII3/m6tsQ QCudmaN0PH3c9/NY0GGm5s5Cza3pynF6nRjkjYJDdwHTUlUcA50HuYKrNd91vPVMziilVt FIwTJ+IN/qcovDeZ7BQl0RqC5+pN6uVm3X/Xpn3aoRuxjav+9WmgJKtTQz4PughdjRmGnF yxdWjZeC9lrbD2SgTPgSGA7runyFxhZKn+DHG9dE+j2+ty00uia82lWpoZR06hp/Q0v3v8 jH7CpoVecr7BFm0PnrRSjAT905LixKvvF6Rk0Gv6gPPVcQyh2FVTVm1tnmaX8A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722544533; a=rsa-sha256; cv=none; b=DaMd/fuJPvBLAlH2dpfNgwCKJmyth7RmrQWpd5NcJGtAvtH5nE423l4bCjnFQHWmQcU4bl +Umx9QMKTPhuhJMwhsIyGtY8hdql4vS7ArYnPrS0cAdjdGik2Q6PjRXri9u4Xrc0SDYOtl Hvve9CjG4/7f5TjxiyREBH8WRzkqwxDgQNNJ0RahVjxdCCPiuTV0/QOf3V3jlqVZgjVhLF rEvfwhPi9jyKSxJMZByK/okqazmobv3LJvn41SheNicGcv0rwfH6/PKuX/yTv/uaWf1w/T jH5Pam6IGMlPBe6iQABMAYuE4RFPf9WJUj/uYiS/H5QnQRP48LM0zsMWZenmMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722544533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2PcRil+nEEM3khN7Uvv17dW+kPToLeJ5ks627W6rfKk=; b=MZvgosca6xd5VP5H6YGGQrR8xRCRuFXe1UL3Iza3zvpuYv1th2l+7mXoFcehORh6YxGZrd ZuNCOE1Xo3pXK2g3i0dmBkiV+L3WW0YaIg1vtqwP4nb8Y1txTKY5cJ4tbsH0BNRzJwg0Ls gKW3iCY0ziOWZf/zrCgOFF2KixvP9c46JaUdxQarKKTCmluRJGilIw0A83tvNEzf7X3GqO SkQ5QFE1xnhPzoeyWHnc97w18HSxaWful9G6LQA0YsNKdAKy1splyv7DR7t8K1+aGoMFFf TcMjl4VWO1u5E4Ng9DbDI9RN357qsJhXWU+Ku5jlNQFru++bcw5UFhsbwp50Pg== 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 4WZghP587Qz10Gc; Thu, 1 Aug 2024 20:35:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 471KZXp4037896; Thu, 1 Aug 2024 20:35:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 471KZXFm037893; Thu, 1 Aug 2024 20:35:33 GMT (envelope-from git) Date: Thu, 1 Aug 2024 20:35:33 GMT Message-Id: <202408012035.471KZXFm037893@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 28391f188ca1 - main - kern_malloc: Restore working KASAN runtime after free() and zfree() folding List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 28391f188ca18b6251ba46040adf81946b0ccb03 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=28391f188ca18b6251ba46040adf81946b0ccb03 commit 28391f188ca18b6251ba46040adf81946b0ccb03 Author: Olivier Certner AuthorDate: 2024-08-01 19:22:56 +0000 Commit: Olivier Certner CommitDate: 2024-08-01 20:35:14 +0000 kern_malloc: Restore working KASAN runtime after free() and zfree() folding In the zfree() case, the explicit_bzero() calls zero all the allocation, including the redzone which malloc() has marked as invalid. So calling kasan_mark() before those is in fact necessary. This fixes a crash at boot when 'ldconfig' is run and tries to get random bytes through getrandom() (relevant part of the stack is read_random_uio() -> zfree() -> explicit_bzero()) for kernels with KASAN compiled in. Approved by: markj (mentor) Fixes: 4fab5f005482 ("kern_malloc: fold free and zfree together into one __always_inline func") MFC after: 10 days MFC with: 4fab5f005482 Sponsored by: The FreeBSD Foundation --- sys/kern/kern_malloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index ebdd00808f22..3c4cb63003c4 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -940,14 +940,18 @@ _free(void *addr, struct malloc_type *mtp, bool dozero) #if defined(INVARIANTS) && !defined(KASAN) free_save_type(addr, mtp, size); #endif - if (dozero) + if (dozero) { + kasan_mark(addr, size, size, 0); explicit_bzero(addr, size); + } uma_zfree_arg(zone, addr, slab); break; case SLAB_COOKIE_MALLOC_LARGE: size = malloc_large_size(slab); - if (dozero) + if (dozero) { + kasan_mark(addr, size, size, 0); explicit_bzero(addr, size); + } free_large(addr, size); break; case SLAB_COOKIE_CONTIG_MALLOC: