From patchwork Wed Mar 25 16:12:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11458277 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 0861F913 for ; Wed, 25 Mar 2020 16:14:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA99A20740 for ; Wed, 25 Mar 2020 16:14:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KZdKDfyo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA99A20740 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 0C8AF6B000D; Wed, 25 Mar 2020 12:14:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0027D6B009B; Wed, 25 Mar 2020 12:14:10 -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 D490A6B009D; Wed, 25 Mar 2020 12:14:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id B67D76B000D for ; Wed, 25 Mar 2020 12:14:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 921AC83EAC for ; Wed, 25 Mar 2020 16:14:10 +0000 (UTC) X-FDA: 76634381460.08.shop87_7bb4cde5f4202 X-Spam-Summary: 2,0,0,eed78c8ff005ed94,d41d8cd98f00b204,3uin7xgykcd8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com,,RULES_HIT:41:152:305: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:2693:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6261:6653:6742:6743:7875:7903:8660:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13148:13221:13229:13230:13846:14093:14097:14181:14394:14659:14721:21080:21365:21433:21444:21451:21627:21939:21990:30054:30064:30070:30090,0,RBL:209.85.128.73:@flex--glider.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.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:23,LUA_SUMMARY:none X-HE-Tag: shop87_7bb4cde5f4202 X-Filterd-Recvd-Size: 5666 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 16:14:09 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id f8so1070701wmh.4 for ; Wed, 25 Mar 2020 09:14:09 -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=VgQgLsqptvNqC9anxeIc1DuP2l9vuZVYJJith3YbZag=; b=KZdKDfyoi+CDUuVEnW3GghtiABZyjqDb8iM1HlQi4VYp5Ikh/ebxjRtqGlByUTHFwk n6CPgyaV5z8x2dRhJHPU1waItoH5FGqr3E69K1D3fH8uT/eM2bYXP0yv7hCzzaAOEBNJ htf/EoiTie/W19VjOJw/622jNxyZLNDiIepaA4LJPJSBXnDlToY53V4apGiOtx0dqhQw M53L+UhR7T2kbVMG2kOfE34riS/1ip5boFKl1OvDvQXLmatH8FyitSqzpAWQGsYT5sKp ocwYXU6v9I/6RdfKVuhLG0RZK76YSAWrRxMciFl4NejW31kC9UO81hXkIs+wUqEXQi4m C9Cg== 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=VgQgLsqptvNqC9anxeIc1DuP2l9vuZVYJJith3YbZag=; b=pabnUebeFwq1xc7D4xWxBcYlYUbbeiP624NjX6jlJobk1iDdmtgZWcQrhMBTdzTZcP HbFbltNDTkGBQFyLUI91S7fuTyqzTMXdzqj2j9LQiStIS7cJjBv1o9ox3StwbVBfQtv+ hEfG2uZ/XUWS1hTg0YVXVP8y8RoWbprRVSrn2rbxU5+bSOl0EBQllrFGEE82fSAhWRsO ruKabbUgAn4Yj/5mCey+pkrdMwlj6Fv7DN9xAI6NJqdg6S/xj4PVP1aXwPCsJRewfLdr 6PEd8wCp1RFSDJe6ePFwR1H7vJ8KhWSYtiDsVAOcVtfetc+KomNfcl7GEhFxrs+7pYgf xG3A== X-Gm-Message-State: ANhLgQ0yHxsmWAJQ4R+B10qfAO3HyFtuGTU7QjK0Lw2DYxsQ66BtkO5D 2bpYiuUZvkZcSViwGskpbNQPxetiufE= X-Google-Smtp-Source: ADFU+vvXQtWt3PMhcVuks8cfm8fLlhdHO/1dOFOF9GE+uTXTwN/LFuknjs9sVN5j4RdGGcJVI3geSOVe6uc= X-Received: by 2002:adf:e946:: with SMTP id m6mr4353064wrn.187.1585152848608; Wed, 25 Mar 2020 09:14:08 -0700 (PDT) Date: Wed, 25 Mar 2020 17:12:34 +0100 In-Reply-To: <20200325161249.55095-1-glider@google.com> Message-Id: <20200325161249.55095-24-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 23/38] kmsan: printk: treat the result of vscnprintf() as initialized From: glider@google.com To: Andrew Morton , Greg Kroah-Hartman , Eric Dumazet , Wolfram Sang , Petr Mladek , Vegard Nossum , Dmitry Vyukov , Marco Elver , Andrey Konovalov , 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, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, ericvh@gmail.com, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, axboe@kernel.dk, m.szyprowski@samsung.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, mhocko@suse.com, monstr@monstr.eu, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com 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: In vprintk_store(), vscnprintf() may return an uninitialized text_len value if any of its arguments are uninitialized. In that case KMSAN will report one or more errors in vscnprintf() itself, but it doesn't make much sense to track that value further, as it may trigger more errors in printk. Instead, we explicitly mark it as initialized. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Andrew Morton Cc: Greg Kroah-Hartman Cc: Eric Dumazet Cc: Wolfram Sang Cc: Petr Mladek Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: Marco Elver Cc: Andrey Konovalov Cc: linux-mm@kvack.org Acked-by: Petr Mladek Reviewed-by: Andrey Konovalov --- This patch was split from "kmsan: call KMSAN hooks where needed", as requested by Andrey Konovalov. Petr Mladek has previously acked the printk part of that patch, hence the Acked-by above. v4: - split this patch away Change-Id: Ibed60b0bdd25f8ae91acee5800b5328e78e0735a --- kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ad46062345452..4cadba3c1e68d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1913,6 +1913,12 @@ int vprintk_store(int facility, int level, * prefix which might be passed-in as a parameter. */ text_len = vscnprintf(text, sizeof(textbuf), fmt, args); + /* + * If any of vscnprintf() arguments is uninitialized, KMSAN will report + * one or more errors and also probably mark text_len as uninitialized. + * Initialize |text_len| to prevent the errors from spreading further. + */ + text_len = KMSAN_INIT_VALUE(text_len); /* mark and strip a trailing newline */ if (text_len && text[text_len-1] == '\n') {