From patchwork Wed Mar 25 16:12:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11458295 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 460D76CA for ; Wed, 25 Mar 2020 16:14:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12F842077D for ; Wed, 25 Mar 2020 16:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HcF3bPHj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12F842077D 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 954F26B00AA; Wed, 25 Mar 2020 12:14:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 88F196B00AC; Wed, 25 Mar 2020 12:14:39 -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 7574B6B00AD; Wed, 25 Mar 2020 12:14:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 527A66B00AA for ; Wed, 25 Mar 2020 12:14:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 36BC1824805A for ; Wed, 25 Mar 2020 16:14:39 +0000 (UTC) X-FDA: 76634382678.01.thing48_7fe2f73b81612 X-Spam-Summary: 2,0,0,d1debd5fe9116e90,d41d8cd98f00b204,3byn7xgykcfwafc78laiiaf8.6igfchor-ggep46e.ila@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:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3870:4250:4321:5007:6261:6653:6742:6743:7875:7903:9969:10004:10400:11026:11658:11914:12043:12048:12295:12296:12297:12438:12555:12895:12986:13069:13311:13357:13846:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21611:21627:30054:30064:30090,0,RBL:209.85.128.74:@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:neutral,Custom_rules:0:0:0,LFtime:33,LUA_SUMMARY:none X-HE-Tag: thing48_7fe2f73b81612 X-Filterd-Recvd-Size: 4763 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 16:14:38 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id s15so873648wmc.0 for ; Wed, 25 Mar 2020 09:14:38 -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=nJyNHCH3d7fYtWRBOT5bbIl4NMJMAEkhfkpvY6wfoBU=; b=HcF3bPHj7jzjxG9fAHkaIPdFhel6b6msvnw7uic6pLKnoDnvZRY0UTs9JViS+zGiJg oVdeni1+hEzSKIfp5cMnt6G9YsAif/6+YXWYGFnyWMmOzX9F23Vawldjo2jGnhbaw3zq QkpmLmrDyiU7ajfiaxNvSfk8UXIuMdpLam1bE92BRookB9SbFELoUHVAZ1L+Hg0/gD4C QNNk+YRh0hSVfvGDY5J/8DaZb/+XM0Kvy7gdu13fMSPaF74FFVW8yZrCtkUROCg8EB5K saBkvgi+SueT9Yyijqg+rxAkY0p+ULFDlItEwH4/zbZ5iccBj8sD/SoinkCEOtOBlk8T NoCA== 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=nJyNHCH3d7fYtWRBOT5bbIl4NMJMAEkhfkpvY6wfoBU=; b=fQOTb1DX0zec+YG+aPPLNAO8EW73cxli28jcwrUAP3xKC+g9/isCFxBjetjEVsyd3I UGWO77y6f0h9w913eI2Hx5K91plmgN0rZ2Os7xyFL+64jRXCLto/Hjl6uYRRtjS5n5eh ssW2PmyqqDrTyxCK3rns2EE34mitL13dcPYoHkiqEHWtscpRofPojjPOLeUXCANt47qW aknKuMZLBBIfl7k+akoAH8NlbxMGKAKF4bIEkfcOJZVlIzYINq7KgqRdtSL/i6nwu9EK 7EWe3lKwGo5f5MG//BbrogEBxp3P5pYgBTa5NqWrk/1vBhy/01dzDNjW/vHQiqH38kP4 ZALQ== X-Gm-Message-State: ANhLgQ2yLn9mXgv0vP0j1MBUttsI5FGRqT5FdE5i7uLOlNVcEa8XUUC4 7U/LXM27z9kG0tHh0182dgKlR2lccE0= X-Google-Smtp-Source: ADFU+vvINOLjtES2nEdJ/29EHkQUc4ebY9GUL2c0x+lDO36gIfkVy5LB5whEru2DqCemqwVrum3kNZbOpts= X-Received: by 2002:adf:afcb:: with SMTP id y11mr4038593wrd.141.1585152877387; Wed, 25 Mar 2020 09:14:37 -0700 (PDT) Date: Wed, 25 Mar 2020 17:12:43 +0100 In-Reply-To: <20200325161249.55095-1-glider@google.com> Message-Id: <20200325161249.55095-33-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 32/38] kmsan: disable strscpy() optimization under KMSAN From: glider@google.com To: 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, akpm@linux-foundation.org, 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, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, 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, pmladek@suse.com, 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, 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: Disable the efficient 8-byte reading under KMSAN to avoid false positives. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: Marco Elver Cc: Andrey Konovalov Cc: linux-mm@kvack.org --- v4: - actually disable the optimization under KMSAN via max=0 - use IS_ENABLED as requested by Marco Elver Change-Id: I25d1acf5c3df6eff85894cd94f5ddbe93308271c --- lib/string.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/string.c b/lib/string.c index 6012c385fb314..fec929e70f1a5 100644 --- a/lib/string.c +++ b/lib/string.c @@ -202,6 +202,14 @@ ssize_t strscpy(char *dest, const char *src, size_t count) max = 0; #endif + /* + * read_word_at_a_time() below may read uninitialized bytes after the + * trailing zero and use them in comparisons. Disable this optimization + * under KMSAN to prevent false positive reports. + */ + if (IS_ENABLED(CONFIG_KMSAN)) + max = 0; + while (max >= sizeof(unsigned long)) { unsigned long c, data;