From owner-dev-commits-src-all@freebsd.org Fri Aug 13 13:58:58 2021 Return-Path: Delivered-To: dev-commits-src-all@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 1C7C1657875; Fri, 13 Aug 2021 13:58: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 4GmQC60HgTz3rF6; Fri, 13 Aug 2021 13:58: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 E6F3D73E7; Fri, 13 Aug 2021 13:58:57 +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 17DDwv9o088220; Fri, 13 Aug 2021 13:58:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17DDwvY2088219; Fri, 13 Aug 2021 13:58:57 GMT (envelope-from git) Date: Fri, 13 Aug 2021 13:58:57 GMT Message-Id: <202108131358.17DDwvY2088219@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: 3d69515cfea2 - main - arc4random: Avoid KMSAN false positives from pre-seeding results 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: 3d69515cfea2781b318ebe1c6e6018d817cde358 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 13:58:58 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3d69515cfea2781b318ebe1c6e6018d817cde358 commit 3d69515cfea2781b318ebe1c6e6018d817cde358 Author: Mark Johnston AuthorDate: 2021-08-13 13:52:05 +0000 Commit: Mark Johnston CommitDate: 2021-08-13 13:58:42 +0000 arc4random: Avoid KMSAN false positives from pre-seeding results If code calls arc4random(), and our RNG is not yet seeded and random_bypass_before_seeding is true, we'll compute a key using the SHA256 hash of some hopefully hard-to-predict data, including the contents of an uninitialized stack buffer (which is also the output buffer). When KMSAN is enabled, this use of uninitialized state propagtes through to the arc4random() output, resulting in false positives. To address this, lie to KMSAN and explicitly mark the buffer as initialized. Reviewed by: cem (previous version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31510 --- sys/libkern/arc4random.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/libkern/arc4random.c b/sys/libkern/arc4random.c index a4bee71c0efd..fd362dd83608 100644 --- a/sys/libkern/arc4random.c +++ b/sys/libkern/arc4random.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -106,6 +107,14 @@ chacha20_randomstir(struct chacha20_s *chacha20) "enabled.\n"); } + /* + * "key" is intentionally left uninitialized here, so with KMSAN + * enabled the arc4random() return value may be marked + * uninitialized, leading to spurious reports. Lie to KMSAN to + * avoid this situation. + */ + kmsan_mark(key, sizeof(key), KMSAN_STATE_INITED); + /* Last ditch effort to inject something in a bad condition. */ cc = get_cyclecount(); SHA256_Init(&ctx);