From patchwork Fri Aug 26 15:07:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956199 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 8345CECAAA3 for ; Fri, 26 Aug 2022 15:09:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 130F694000B; Fri, 26 Aug 2022 11:09:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BAB5940007; Fri, 26 Aug 2022 11:09:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E776894000B; Fri, 26 Aug 2022 11:09:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D34EB940007 for ; Fri, 26 Aug 2022 11:09:26 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B4A76AC311 for ; Fri, 26 Aug 2022 15:09:26 +0000 (UTC) X-FDA: 79842077532.03.1FCB6B4 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf02.hostedemail.com (Postfix) with ESMTP id 5EB9680021 for ; Fri, 26 Aug 2022 15:09:26 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id hr32-20020a1709073fa000b00730a39f36ddso715324ejc.5 for ; Fri, 26 Aug 2022 08:09:26 -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; bh=78OHj/gzoCKqAY5c+j3k9RRp1IwnWy2nlunSdcq054Y=; b=infDBXfaloZqVmGL5DNRFAfhMOqS8NqxfxjZ9dKspnlgueeDAHoYYH+4Gi8exWGIuo Nw/AkcesiN61mybTdSO3jhwM5TKCtIZhjXZo1HG7sK+cjrWBUsaf4R/cHM2iBvYj2bOA WkeD3rhneP4hNHRSfpfEujFgSGje7KupjxgjkfUMA9MS0vN6o7veSyC7WryDqeiljwvb FmhY2QfU0D3vj7dQTHo2CxstSRJlqjkORV6jtBYWg/wZqUdM5bvjWUyfkBV2EDhFtv/1 Hn+WikD7nGPTrxjpCCiMPssZSlPqnH7OceYjz25N+b1EK3r2roffSRjICRe9X9QMXNjz qm8g== 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; bh=78OHj/gzoCKqAY5c+j3k9RRp1IwnWy2nlunSdcq054Y=; b=kj1iiPOtz+lt3Xh0a09RhviHFm6rEZiUMkqV1QTeVlA5/rm2FS4kXrZRvcSRv7AT33 xm8LaSHd3JYLnFAi5IDyM5ynC9rrLWJmgflsySfoAhx8tWW6AAVluqOukHsUQHxMv3gK claBsg7pamGKeVxO6TJFDXrt8GJWZmI6wYqgwe9XZzXyRudRNcO7IH8B+5d92h9VPdrH /ONjNGT4GGtvE1nB41WYvpirylHTOSsp02c4uvC7VEm4k4dehtFmcpZv/oooAaYb+VUL eXoOzZvozWLcQDezP1z1zPBloBKLcAGDxJa7kjgAouD4kvgT7/X3Y++nxDzkYfVKyfIn B9nQ== X-Gm-Message-State: ACgBeo2crxUZuesyY1J8Jvw/Gwp5ktm9RKFGYC/zsLkuPd/RlEW/ExUN r9v/+djCeJeWYFGCNv8SS+Angk/eP9w= X-Google-Smtp-Source: AA6agR6OeypAkAbsTcwRMz6skRqVX67u6RKiOQC813CDO+HQWRif6q4KXUdIv6HG7IvLOSgOm7Y2kqCqBbc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a50:fc17:0:b0:446:861b:ee10 with SMTP id i23-20020a50fc17000000b00446861bee10mr7463262edr.251.1661526565221; Fri, 26 Aug 2022 08:09:25 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:49 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-27-glider@google.com> Subject: [PATCH v5 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=1661526566; a=rsa-sha256; cv=none; b=A/zR86JrGg5/Xl1i0nXJJpsmrgviEYpLignx4JiKNC59r019DHIFbDXJ+8/kZXX8UM66PJ ca0cpzGnWNQ+ybvAVd01CVN52ms+Z79MbUBz+yFkffYx9bDfQogRaXh5/7MM1/0/dVkygW tkcEqUxK6At42G1kMkF3MBNCl5Gz/ss= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=infDBXfa; spf=pass (imf02.hostedemail.com: domain of 3JeIIYwYKCCwOTQLMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3JeIIYwYKCCwOTQLMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@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=1661526566; 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=78OHj/gzoCKqAY5c+j3k9RRp1IwnWy2nlunSdcq054Y=; b=AC2S6reVq1kwUTWSV8kcLkSmz41Pp2XkyUnJ68qvWC3ntnF+QHqeG2Zuc2fYQ17f9tcDRq o6Juj8xfo/coJoEJ1yiE9vdZL2Sx8ls4IDTibCjrnmJMDNV7uomjX0IdP0Ps70jti7RUvK gPhGKHUNLpjbZOXCSVReJmMYl2j/T8k= X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=infDBXfa; spf=pass (imf02.hostedemail.com: domain of 3JeIIYwYKCCwOTQLMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3JeIIYwYKCCwOTQLMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam10 X-Stat-Signature: jgqjxeuczgjdtipcs6tfud5errsjkp74 X-Rspamd-Queue-Id: 5EB9680021 X-HE-Tag: 1661526566-577955 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;