From patchwork Fri Jul 1 14:23:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12903400 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 2FD4BC43334 for ; Fri, 1 Jul 2022 14:25:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC6726B0071; Fri, 1 Jul 2022 10:25:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B76696B007E; Fri, 1 Jul 2022 10:25:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A174C6B0081; Fri, 1 Jul 2022 10:25:17 -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 9159F6B0071 for ; Fri, 1 Jul 2022 10:25:17 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 65758205D4 for ; Fri, 1 Jul 2022 14:25:17 +0000 (UTC) X-FDA: 79638753474.15.C8B654C Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf05.hostedemail.com (Postfix) with ESMTP id 0B75F100054 for ; Fri, 1 Jul 2022 14:25:16 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id x8-20020a056402414800b0042d8498f50aso1888171eda.23 for ; Fri, 01 Jul 2022 07:25:16 -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=/n5egAWhgjqHJF7YploSYMAs3TFFsaM1JiTS0Bn58vA=; b=Q64KAy7Oa2nU5QEGyiPc+WuoNDDnAlGeuwj9Gnp4CxbUOEi4OI3mY3DVAxjpBiKgfy oa7qyOyW4RhD6IyTiejiC7YtXEPcWRYAw5gxMRCHiOP9br49u9DBYFU0wT8izXo989yb SsJ683z3889b7saADkdB2NmfOQkA9W3PR5kSJXdTK6rlAIAn/matyXusT0WxYIYR1PdC nsJAkTFlORzo0vstvDMrGlx6qd2DiIZ3JP81lA81CBvxEItVe4LQpcoX5OTFruunfhnn 6Il7stXu45y2U2bIykk0AFttgTTdTXs+YT4Idf4maBbQ8qhqqM+TVsUW/CeEtqqLOi3k x6Qw== 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=/n5egAWhgjqHJF7YploSYMAs3TFFsaM1JiTS0Bn58vA=; b=jU+u4VhMhUNjmBSSuwdcy2raG/7gotzV78jwOA+8KB3KOt7HVH2ZUX+2/QyL+yTB33 kOw/eD+nZUKruL6MSmhgrepdknn8m7WnY/OIQwv30McmawZkuzckg7E/IBwlOOUln0SM VitF5rIYkzRBkM+Dnvj2/TS+QV6tyT1fULFHFpXETHRkN/MfbzSXF46HrrLXND/dRBYF Oz7jJ2+F68LaCqeII17RggjMCC7WM+8nCd65b9GG8D+nOCUvKddBZo5hxKwQkrweHoEH 8XW/DAzNWdrD6a5JU5qFKNvUdIGc2c1Jb0JSMommKkFqUq7SZQdzXdiYzqFOrGVV5ui8 ztYw== X-Gm-Message-State: AJIora8IZTk2t75so2Ik0SkpXtmpAL/v2Xpm3UIilM+aMLRU0/YW7dJ4 znmOk9/HXQ+RBGJ9X5SRoBkULPCScyA= X-Google-Smtp-Source: AGRyM1vUh8ZooMqVrhXc2xeGCFSNfOoXJqVl3ZPA1oCNI4qUloUIWKz76DRGg3RXhdunivVizxxEE/eITwE= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a05:6402:51ca:b0:437:79a9:4dd with SMTP id r10-20020a05640251ca00b0043779a904ddmr19173589edd.319.1656685515729; Fri, 01 Jul 2022 07:25:15 -0700 (PDT) Date: Fri, 1 Jul 2022 16:23:08 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-44-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 43/45] namei: initialize parameters passed to step_into() 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, Evgenii Stepanov , Linus Torvalds , Nathan Chancellor , Nick Desaulniers , Segher Boessenkool , Vitaly Buka , linux-toolchains@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656685517; a=rsa-sha256; cv=none; b=DJq32Jw0iMhTBAItyr6pPKvdy5b977l7bj08mJDOyNKv3b/saVgOer294gpX1l5Zt2HZ/j hSqri981kQJaWpbKJ3M5wh6n/8MAhaY/7jYAqJ00Du+G9g6G+vbLqeu3oEy9YSa39/V9oY TRHFerfsATzyvqasAM5+doXUPC9+rGU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Q64KAy7O; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3ywO_YgYKCOoSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3ywO_YgYKCOoSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656685517; 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=/n5egAWhgjqHJF7YploSYMAs3TFFsaM1JiTS0Bn58vA=; b=AYq8GtWH7wgKUcyON11X/Pm+goQXrTWCo5D6rxQiYVbpKAFu2tVtgr4qoDPaxaT0eQIWQ4 5RBK9i6jbBVCyhS1R3QWGcV5Nid9/ZHz3Ev+0OPhjCAujObM2i1z5bzZQ0IxTUtXJkQrHv k6uTNCM2MKD2hRwImf5E/h2e/U8jZPY= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0B75F100054 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Q64KAy7O; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3ywO_YgYKCOoSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3ywO_YgYKCOoSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com X-Rspam-User: X-Stat-Signature: k35qk97jkw1ci51tpietwz7joj1eu68f X-HE-Tag: 1656685516-166560 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: Under certain circumstances initialization of `unsigned seq` and `struct inode *inode` passed into step_into() may be skipped. In particular, if the call to lookup_fast() in walk_component() returns NULL, and lookup_slow() returns a valid dentry, then the `seq` and `inode` will remain uninitialized until the call to step_into() (see [1] for more info). Right now step_into() does not use these uninitialized values, yet passing uninitialized values to functions is considered undefined behavior (see [2]). To fix that, we initialize `seq` and `inode` at definition. [1] https://github.com/ClangBuiltLinux/linux/issues/1648#issuecomment-1146608063 [2] https://lore.kernel.org/linux-toolchains/CAHk-=whjz3wO8zD+itoerphWem+JZz4uS3myf6u1Wd6epGRgmQ@mail.gmail.com/ Cc: Evgenii Stepanov Cc: Kees Cook Cc: Linus Torvalds Cc: Marco Elver Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Peter Zijlstra Cc: Segher Boessenkool Cc: Thomas Gleixner Cc: Vitaly Buka Cc: linux-kernel@vger.kernel.org Cc: linux-toolchains@vger.kernel.org Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/I94d4e8cc1f0ecc7174659e9506ce96aaf2201d0a --- fs/namei.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1f28d3f463c3b..6b39dfd3b41bc 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1995,8 +1995,8 @@ static const char *handle_dots(struct nameidata *nd, int type) static const char *walk_component(struct nameidata *nd, int flags) { struct dentry *dentry; - struct inode *inode; - unsigned seq; + struct inode *inode = NULL; + unsigned seq = 0; /* * "." and ".." are special - ".." especially so because it has * to be able to know about the current root directory and @@ -3393,8 +3393,8 @@ static const char *open_last_lookups(struct nameidata *nd, struct dentry *dir = nd->path.dentry; int open_flag = op->open_flag; bool got_write = false; - unsigned seq; - struct inode *inode; + unsigned seq = 0; + struct inode *inode = NULL; struct dentry *dentry; const char *res;