From patchwork Sun Nov 19 22:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 166905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1870575vqn; Sun, 19 Nov 2023 14:59:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwvhdLaPuPSJOYW171GJZrh7n08GXso/Bq5Zy37ySIAOV8a+krHSWW2LEAr0l90O140WwP X-Received: by 2002:a17:90b:314c:b0:280:72b:397d with SMTP id ip12-20020a17090b314c00b00280072b397dmr16215389pjb.20.1700434786159; Sun, 19 Nov 2023 14:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700434786; cv=none; d=google.com; s=arc-20160816; b=MbeCYqMjmw/KE7frZD1BEPuJDACMLppNd/WCjQQJoeTV69uNFugeoEYKEELTX8UAsM rRSIxQpINxaO0IlwqclQNSaMTfdR+wvb/qVA/OSURUL2pRD1Qwm1pJU8OqC1nB2fqdm/ qBIueJGzYtU7J1/OaT5A6W7m4X1OfpHk5k4qsbeJ6oBaUZMco61ihJFhAbLa29+aw0Hn 62HYdnu497TBJiTumHsGuZbkyUJE+mxeq41m4LJ+8t0/5tPu3AXn3+YZdej+E8ZXEdu0 KAkiuqWlZNGm5eRNDwyoS/3Bocz+ntBTQKTZD4oR30BFrmhmNUJXRFt4KrPxaXZV1kuP eTPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=macCbamwOc+AOpRNoahohAS+AkBgWnzHm+Fum2aOpq4=; fh=NgjoLSA/cFml66RbTiPwTYFkNlfHfz/KSqC8Agsw6ss=; b=GOyuvcdzqr42WQVtWHdZW57+VHh97qCkDNC+8MPwarl48RQsImkHpBfkD0a+64Yjb/ T1w/DefT/KPL8p1R4l/r1Mf36h6pwVf8DE6kt/1CAHtjlE9YO1gWlTygRfpsoNdYoLY/ rI7baDQlYkBn1doH0t2/HIm1u4SqPSQIhGROP4sb03gVRoYr4muxDPUzXQ6nvQVxwPTX 5LYvDP2W0+jGRgDtR9wquXwxneEye1t4MvEMVZZB4v0rFeEe+lG1qug2FL5j7kxB1+85 qkqCgxS+xugME6h4iLhouI8bnSpqlIU09vXFraZMPqfZS1OVGw0UUu0j9+GXHY7iqOn0 Fuzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id pf2-20020a17090b1d8200b00282ecadd91csi9890012pjb.15.2023.11.19.14.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 14:59:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DDA438059DB3; Sun, 19 Nov 2023 14:59:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbjKSWxt (ORCPT + 28 others); Sun, 19 Nov 2023 17:53:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjKSWxs (ORCPT ); Sun, 19 Nov 2023 17:53:48 -0500 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E4749E; Sun, 19 Nov 2023 14:53:45 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 6AF7F1002E8; Mon, 20 Nov 2023 09:53:40 +1100 (AEDT) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DzoD7MaJF9yt; Mon, 20 Nov 2023 09:53:40 +1100 (AEDT) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 5FD251002F5; Mon, 20 Nov 2023 09:53:40 +1100 (AEDT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 Received: from donald.themaw.com (2403-580f-7fe0--101a.ip6.aussiebb.net [IPv6:2403:580f:7fe0::101a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ian146@aussiebb.com.au) by smtp01.aussiebb.com.au (Postfix) with ESMTPSA id 957AD100282; Mon, 20 Nov 2023 09:53:38 +1100 (AEDT) From: Ian Kent To: Al Viro , Christian Brauner Cc: Bill O'Donnell , Kernel Mailing List , autofs mailing list , linux-fsdevel , Ian Kent , syzbot+662f87a8ef490f45fa64@syzkaller.appspotmail.com Subject: [PATCH v2] autofs: add: new_inode check in autofs_fill_super() Date: Mon, 20 Nov 2023 06:53:19 +0800 Message-ID: <20231119225319.331156-1-raven@themaw.net> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 14:59:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783035106028053480 X-GMAIL-MSGID: 1783035106028053480 Add missing NULL check of root_inode in autofs_fill_super(). While we are at it simplify the logic by taking advantage of the VFS cleanup procedures and get rid of the goto error handling, as suggested by Al Viro. Signed-off-by: Ian Kent Cc: Al Viro Cc: Christian Brauner Cc: Bill O'Donnell Reported-by: syzbot+662f87a8ef490f45fa64@syzkaller.appspotmail.com Reviewed-by: Bill O'Donnell --- fs/autofs/inode.c | 59 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index a5083d447a62..6ecf68536240 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -311,7 +311,6 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc) struct inode *root_inode; struct dentry *root; struct autofs_info *ino; - int ret = -ENOMEM; pr_debug("starting up, sbi = %p\n", sbi); @@ -328,56 +327,42 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc) */ ino = autofs_new_ino(sbi); if (!ino) - goto fail; + return -ENOMEM; root_inode = autofs_get_inode(s, S_IFDIR | 0755); - root_inode->i_uid = ctx->uid; - root_inode->i_gid = ctx->gid; - - root = d_make_root(root_inode); - if (!root) - goto fail_ino; - - root->d_fsdata = ino; + if (root_inode) { + root_inode->i_uid = ctx->uid; + root_inode->i_gid = ctx->gid; + root_inode->i_fop = &autofs_root_operations; + root_inode->i_op = &autofs_dir_inode_operations; + } + s->s_root = d_make_root(root_inode); + if (unlikely(!s->s_root)) { + autofs_free_ino(ino); + return -ENOMEM; + } + s->s_root->d_fsdata = ino; if (ctx->pgrp_set) { sbi->oz_pgrp = find_get_pid(ctx->pgrp); - if (!sbi->oz_pgrp) { - ret = invalf(fc, "Could not find process group %d", - ctx->pgrp); - goto fail_dput; - } - } else { + if (!sbi->oz_pgrp) + return invalf(fc, "Could not find process group %d", + ctx->pgrp); + } else sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID); - } if (autofs_type_trigger(sbi->type)) - __managed_dentry_set_managed(root); - - root_inode->i_fop = &autofs_root_operations; - root_inode->i_op = &autofs_dir_inode_operations; + /* s->s_root won't be contended so there's little to + * be gained by not taking the d_lock when setting + * d_flags, even when a lot mounts are being done. + */ + managed_dentry_set_managed(s->s_root); pr_debug("pipe fd = %d, pgrp = %u\n", sbi->pipefd, pid_nr(sbi->oz_pgrp)); sbi->flags &= ~AUTOFS_SBI_CATATONIC; - - /* - * Success! Install the root dentry now to indicate completion. - */ - s->s_root = root; return 0; - - /* - * Failure ... clean up. - */ -fail_dput: - dput(root); - goto fail; -fail_ino: - autofs_free_ino(ino); -fail: - return ret; } /*