From patchwork Mon Sep 5 12:24:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12966057 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 98A3BECAAD3 for ; Mon, 5 Sep 2022 12:26:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FC6D8D0081; Mon, 5 Sep 2022 08:26:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D3188D0076; Mon, 5 Sep 2022 08:26:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 173688D0081; Mon, 5 Sep 2022 08:26:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 07C778D0076 for ; Mon, 5 Sep 2022 08:26:11 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D340B140D95 for ; Mon, 5 Sep 2022 12:26:10 +0000 (UTC) X-FDA: 79877954100.19.4B7ED9F Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf25.hostedemail.com (Postfix) with ESMTP id 7E3AEA0079 for ; Mon, 5 Sep 2022 12:26:10 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id qf22-20020a1709077f1600b00741638c5f3cso2291190ejc.23 for ; Mon, 05 Sep 2022 05:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=PRETZsLeKtd8er/vGZIvwJ67UbRQnpYPS7VnNd6iitc=; b=Rw0JSo2mfA53wv1KbqcCFIJoJCKgB38eiEtze1NtffAs06/flW4T57bbg2dVgmm7vN Qgo1uiqbKJaHLIYDDiLsbIbsnOBwXkyph/jL1jJt7c88fQk6BTFd9sFusdBxHhx6dDYE u5T3ewW3kKrqDUiYOfyUWYtYPe4wTLLwz6YktJHkCggWgZlXMaXpy8DUIH24zJx2XEu5 /2ZJizHYM8tdojTqRxVSOKMfWIBfh4BQZl9kEZRZrxqDuXDq6LhgmA36ysx4Fnd4wn/z RXSYyqOZGt5AmWmyGx3znX+g0JifZp9ZClGm7haZUkqafRea3A16fYJTpOu+ONa6qpWB P9rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=PRETZsLeKtd8er/vGZIvwJ67UbRQnpYPS7VnNd6iitc=; b=yDFMhvOifu49awYlUJFEUnL/FPw+bC9zRmiqk+TUfBWThTYVS8SorhnWeyBpGQ1iaS kOYYpXhEPkTMopiZ6uhHEcSBG1/Y+FoJxkdvEVPS94d0WMohdnmvmJ8NyTRWEQqkldme HSvp6mXd02CQJYzUgisKet0FSXvKQRPO2P5pZvXFyv+dhnahFll3hHbTw67I5VESkEm3 9VmSLatcDXcn6AMlfGLznu+cfBHqx59u9fkBRUKnNqnOZBi9l1N1EYTeuxoAFdqfxfH+ ZufKCUAbIckA2bywxDK36owh5Dz2z5xmJ65/n64VAcHbAcOa83IWtxUq0i4VlqhEdVet I7OA== X-Gm-Message-State: ACgBeo1CRWSGKFijREVimTImVmaJjXFzEMmXZhqBq33MP8sVpToaTkLh VzuRtwBZuIKHdK/acylnFvwtfMsr8yc= X-Google-Smtp-Source: AA6agR6H7t7tR3hDwMYsSl5f8ymL7keGAQBGQoCYb8T9aH1rg12oi88mnhysrWMbCn39pKzombeP5qdOg3Y= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b808:8d07:ab4a:554c]) (user=glider job=sendgmr) by 2002:a05:6402:4515:b0:443:7833:3d7b with SMTP id ez21-20020a056402451500b0044378333d7bmr18008265edb.151.1662380769211; Mon, 05 Sep 2022 05:26:09 -0700 (PDT) Date: Mon, 5 Sep 2022 14:24:34 +0200 In-Reply-To: <20220905122452.2258262-1-glider@google.com> Mime-Version: 1.0 References: <20220905122452.2258262-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220905122452.2258262-27-glider@google.com> Subject: [PATCH v6 26/44] kmsan: disable strscpy() optimization under KMSAN From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , 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 , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662380770; a=rsa-sha256; cv=none; b=bjQuBkdspkRtgE37zb19OkWpWexQiBvmE66rIwmTkQ61V+oZ6vpldSNAb1SGBnb0fGdJAt L6o0KuAqh0cTmmwIy5s1nyRXjTl0Y7qZtR1u4x8GQHs463D2V9iqri+QxyaKaUpLRuXrBq JidoDtyXVsFTjzZ9lRIEGFKM88KI4Es= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Rw0JSo2m; spf=pass (imf25.hostedemail.com: domain of 34eoVYwYKCC4QVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=34eoVYwYKCC4QVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662380770; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PRETZsLeKtd8er/vGZIvwJ67UbRQnpYPS7VnNd6iitc=; b=p8lL4SR1wHyIz9qGIfJWQ+UV2ETN+IZpsM5MQBNTf3C4C6CTIJAEnPbxHv+B1wnA3dEHz8 j4nhBGCVoMRHaX7HtMAe8u6FbVp4rIsyS+faDVpKged3Zmgdn+NUWfF0rhL5GCut24nzrB YP72LlEOh4W50DnwnSRnZT8vtxnnSuI= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Rw0JSo2m; spf=pass (imf25.hostedemail.com: domain of 34eoVYwYKCC4QVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=34eoVYwYKCC4QVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: u9a6qt6h7qnidg9msbow486sxqn9dr4z X-Rspamd-Queue-Id: 7E3AEA0079 X-HE-Tag: 1662380770-940045 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 6f334420f6871..3371d26a0e390 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;