From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A785C433EF for ; Fri, 1 Jul 2022 14:30:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233134AbiGAOaR (ORCPT ); Fri, 1 Jul 2022 10:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232849AbiGAO3Z (ORCPT ); Fri, 1 Jul 2022 10:29:25 -0400 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB94661D5B for ; Fri, 1 Jul 2022 07:25:22 -0700 (PDT) Received: by mail-ej1-x64a.google.com with SMTP id qf29-20020a1709077f1d00b00722e68806c4so835257ejc.4 for ; Fri, 01 Jul 2022 07:25:22 -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=vEhIb/Bliezgrv5EMxYr4+hvXzVTcAXebx43H5cFyM+Mz15ZxdT/gbqrChpx0Ace3J o1SYOm+aLfzCQyxzXNtznzrGtSm+MbjkGlVx1guVHt8jlL2zxuPAOpxufp+VE4XOC9cW yUqADRufuN/fyEPlfJZG1EU/xwfVvTrcU4y8FCTAe0lYvkntbzNlbffMfkFlEgg2T+34 C5j74rMADVKMxCyc3wWkeuISRDHqQAQstfzYScxAckE4388jm4H1cZswF0XN8zzXVQYF fbAeQr6lIg2JthKdmRfO9h5rPkAxXjGIKAm1g8ZV55WxC6TTb92ZGKPbWlvgoqU1vceK uqiA== X-Gm-Message-State: AJIora/1OHl2c+30EtKnxCw4fzSv+wNKIpVNrx4OZKaEwettLf0A61Bd ho7gj4aaak+sfbLyyTdCMyzpibqgm18= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.37.0.rc0.161.g10f37bed90-goog