From patchwork Wed Mar 25 16:12:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11458291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28EB0913 for ; Wed, 25 Mar 2020 16:14:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA4C020409 for ; Wed, 25 Mar 2020 16:14:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cAfnE1Vw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA4C020409 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 733536B00A6; Wed, 25 Mar 2020 12:14:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6BABF6B00A8; Wed, 25 Mar 2020 12:14:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 559926B00A9; Wed, 25 Mar 2020 12:14:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 338076B00A6 for ; Wed, 25 Mar 2020 12:14:33 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2142B181C34EF for ; Wed, 25 Mar 2020 16:14:33 +0000 (UTC) X-FDA: 76634382426.01.part71_7f04677504043 X-Spam-Summary: 2,0,0,5cac5703c7b4ec93,d41d8cd98f00b204,3z4n7xgykcfy49612f4cc492.0ca96bil-aa8jy08.cf4@flex--glider.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2904:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3870:3872:3874:4321:5007:6261:6653:6737:6742:6743:7514:9969:10004:10400:11026:11232:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13161:13229:13846:14093:14097:14181:14394:14659:14721:21060:21080:21365:21444:21451:21627:21990:30034:30045:30054:30064:30090,0,RBL:209.85.128.74:@flex--glider.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: part71_7f04677504043 X-Filterd-Recvd-Size: 5865 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 16:14:32 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id m4so2668417wme.0 for ; Wed, 25 Mar 2020 09:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=a+HHqC0dc7Q+M3lI9Kv2dExasURR+VQ+5gFn0GtjCWE=; b=cAfnE1Vw95Kp8qMfCrgctDsXy9lALLxqUKdaO5dg621kfxeZIeQOy/e/oHNgln3Yto BQ/NF6SjCovsR9RMfAUyijxqRvvkQwVt5PiGFARUSGo0y24zBpgJjd/HKY95mhHlnm7E NyOn8PHghpYSpgc51B6MGBbf5niPFP6HHQYeAE0sp4tz9zkNUZDvpA9IVdcD8rp+2MEw b5LKuE+3eEwtXJSrCVT8sKjCdzCZbYLAddpbifjUHOKywfx7WgU+ddGJ0XAMFnS8mMsE mmn6TH2DyZLhBJkgguwmcTBWwO57d4kpl/t/cKAE8q9BCljqN2NeyNXtOinv2FnqF2iD h4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=a+HHqC0dc7Q+M3lI9Kv2dExasURR+VQ+5gFn0GtjCWE=; b=q56nJ8OTedkvbPbboOZOEZ6pz2SVGtHf5xdlUoR7tQOWJewLvK6Op5DBKwWfuAgQDQ MJP+jXXVCiFw+/XLZXL//hBKViKNA0bTd3Rfz5Gdesed7ozfiw4qs8rclUMnidcRtlz5 xQnOdIbmqTvc/rQ+n1BQ5VXNKGeVcJoCYh7qQ//aVOiFgzy0A7crAir65dWThXHnelAT rub7BWLkJSYfl3cT33Ncr6b6zdg25XbTbiL2/yDBg9tqYd0IExp/y6ZiElSVWqf5nBK3 AtcZVNMZFkn1RidzwmHIJ1OUTvl121e0JvnhRwvqJSxht0IqgiPRvqAWVprayu8bATcI kGSQ== X-Gm-Message-State: ANhLgQ3cbiGMatrg2H7fIYXx8DvjfzBbDz+i/UGDc7alGjTmY4YUMKbW 4Hp7VZ7ravLKSAhB+Zyx//5LCUrPU7I= X-Google-Smtp-Source: ADFU+vs9PPJ+u32WNl22gimU/x02Zgiy0Z9QDgDzx7/LlYQ88GNvA93T6s+4y6YFpZu/q0/bL/DG9SEdlBA= X-Received: by 2002:a5d:540c:: with SMTP id g12mr4456924wrv.178.1585152871215; Wed, 25 Mar 2020 09:14:31 -0700 (PDT) Date: Wed, 25 Mar 2020 17:12:41 +0100 In-Reply-To: <20200325161249.55095-1-glider@google.com> Message-Id: <20200325161249.55095-31-glider@google.com> Mime-Version: 1.0 References: <20200325161249.55095-1-glider@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v5 30/38] kmsan: handle /dev/[u]random From: glider@google.com To: Andrew Morton , Jens Axboe , "Theodore Ts'o" , Dmitry Torokhov , "Martin K. Petersen" , "Michael S. Tsirkin" , Christoph Hellwig , Eric Dumazet , Eric Van Hensbergen , Takashi Iwai , Vegard Nossum , Dmitry Vyukov , Marco Elver , Andrey Konovalov , Matthew Wilcox , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, darrick.wong@oracle.com, davem@davemloft.net, ebiggers@google.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, m.szyprowski@samsung.com, mark.rutland@arm.com, schwidefsky@de.ibm.com, mhocko@suse.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The random number generator may use uninitialized memory, but it may not return uninitialized values. Unpoison the output buffer in _extract_crng() to prevent false reports. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Andrew Morton Cc: Jens Axboe Cc: "Theodore Ts'o" Cc: Dmitry Torokhov Cc: Martin K. Petersen Cc: "Michael S. Tsirkin" Cc: Christoph Hellwig Cc: Eric Dumazet Cc: Eric Van Hensbergen Cc: Takashi Iwai Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: Marco Elver Cc: Andrey Konovalov Cc: Matthew Wilcox Cc: linux-mm@kvack.org Reviewed-by: Andrey Konovalov --- This patch was previously known as "kmsan: unpoisoning buffers from devices etc.", but it turned out to be possible to drop most of the annotations from that patch, so it only relates to /dev/random now. Change-Id: Id460e7a86ce564f1357469f53d0c7410ca08f0e9 --- drivers/char/random.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/char/random.c b/drivers/char/random.c index 0d10e31fd342f..7cd36c726b045 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -322,6 +322,7 @@ #include #include #include +#include #include #include #include @@ -1007,6 +1008,11 @@ static void _extract_crng(struct crng_state *crng, spin_lock_irqsave(&crng->lock, flags); if (arch_get_random_long(&v)) crng->state[14] ^= v; + /* + * Regardless of where the random data comes from, KMSAN should treat + * it as initialized. + */ + kmsan_unpoison_shadow(crng->state, sizeof(crng->state)); chacha20_block(&crng->state[0], out); if (crng->state[12] == 0) crng->state[13]++;