From patchwork Tue Mar 29 12:40:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12794782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6040C433EF for ; Tue, 29 Mar 2022 12:41:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B67B8D0010; Tue, 29 Mar 2022 08:41:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5663C8D000F; Tue, 29 Mar 2022 08:41:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45A2E8D0010; Tue, 29 Mar 2022 08:41:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 307AA8D000F for ; Tue, 29 Mar 2022 08:41:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 13FC4606CD for ; Tue, 29 Mar 2022 12:41:57 +0000 (UTC) X-FDA: 79297385874.10.471CFDD Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf25.hostedemail.com (Postfix) with ESMTP id 89EE9A0009 for ; Tue, 29 Mar 2022 12:41:56 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id i4-20020aa7c9c4000000b00419c542270dso5230674edt.8 for ; Tue, 29 Mar 2022 05:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RDAmLqPngdYXKHnjNo9GDMAFOLr0Hdlw9RyMH9Gzg2s=; b=FNcO9gUSy3+PyH4e35W5RF6+lKn5SBE99oNAhVPz9pbYEq9m/C8L6ZgtW5ZmHXHd88 hQHJyPhLbOckmp0EqPMhP2HFzsxaGQxiGxliYPsshxLsXZvRvNDQ3UiI+w2rcId/Pty2 F64ZcwqpBt31uCBn0TdlaFTImU9JlBg1RYV2VHIqSgThEHMQahV/qTUZD+t5uPqd7ue6 fH/tn196F1PiJHLimD7A+gQDUww4aLBtiNt+XEamDrdfD269XRiydzui+vDM+yTJPgEp rF70JXIzeqHaym/T57YbYOQSbgbJ7VSdFIY7t07gue+zb/IWNfau8QfmJWCRW+7p6THF iMvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RDAmLqPngdYXKHnjNo9GDMAFOLr0Hdlw9RyMH9Gzg2s=; b=mbJ2rMssxiWQLOD1bqQq8p5mMRlFWJzgax6nYvLYgX/e8+hTbI7gIx2I5BW4Ua+pVy 6AjtJov7hpiY+JE2r22qHM9ThkDRcK6jSQYGqiJVuZzG19L8K8I4Hk79hkSq3pgNlOZz BJN/3Y9w1wgl+nLVA2X606Isk6CWV9yediM7uQWqMCSENxf9ShA5kwd0e38ZU0GG6rJK /LYaf/UDlKxXvVO19hFLoLa037mxYPZPaK4lzGfFrzh0ZflZBAcBS+0KWl3H3MJ+0cf+ x+3j0KlboKRjcB0iwaKyBI9k4Bq7RaD3rpM0znQuDE9411EgcAz/Eizs+IG58QIKBLCZ 5fsg== X-Gm-Message-State: AOAM531CIWAcyoi4bvMeZIgXHMshb4twfxSKnXppd9TTyYGCheRAtdwb d2y+DJ7OHPaslbxLYF776peEx3Tg1Ho= X-Google-Smtp-Source: ABdhPJzvRP1sTqhryqj6ueAWd65Bk5TF0Xd1dq7WPSkbBowXyk0DvSiadnoCaN6qak+2HIZ7cYi2Zk2fLDo= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:36eb:759:798f:98c3]) (user=glider job=sendgmr) by 2002:a17:906:af6b:b0:6df:83a9:67db with SMTP id os11-20020a170906af6b00b006df83a967dbmr34685899ejb.222.1648557715258; Tue, 29 Mar 2022 05:41:55 -0700 (PDT) Date: Tue, 29 Mar 2022 14:40:01 +0200 In-Reply-To: <20220329124017.737571-1-glider@google.com> Message-Id: <20220329124017.737571-33-glider@google.com> Mime-Version: 1.0 References: <20220329124017.737571-1-glider@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 32/48] kmsan: disable strscpy() optimization under KMSAN From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: mx7yms1pjpfxr7omturooiz8tqqfiub9 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FNcO9gUS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3k_5CYgYKCLQafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3k_5CYgYKCLQafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com X-Rspamd-Queue-Id: 89EE9A0009 X-HE-Tag: 1648557716-462174 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 --- Link: https://linux-review.googlesource.com/id/Iffd8336965e88fce915db2e6a9d6524422975f69 --- lib/string.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/string.c b/lib/string.c index 485777c9da832..4ece4c7e7831b 100644 --- a/lib/string.c +++ b/lib/string.c @@ -197,6 +197,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;