From patchwork Thu Sep 28 13:11:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 146357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3675153vqu; Thu, 28 Sep 2023 16:53:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEb62eGrp9UizToZgJoHW3f4Xdiub/p2a6PltwkScbiJTUKmsATRAQV53M6NWp/NCTcfqsa X-Received: by 2002:a05:6a21:19c:b0:160:c502:6d8b with SMTP id le28-20020a056a21019c00b00160c5026d8bmr3060236pzb.7.1695945206738; Thu, 28 Sep 2023 16:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695945206; cv=none; d=google.com; s=arc-20160816; b=mTYUSnOOief+i+OnH0FXBjlpb48367Z5aoUbShDrqAeQtVIwjK12DM7spg8OZ2LyxI deJrK5nAcn/ONdh4ku4zZPHlO/xJUujm+adXTmRu2Im+wvDQNZNs7WqPlaPwMwAbWMaU 1tXUFj/MBptlvfPnnx3mJh65gX3oev1msPCv7THUI5g0htXNh7bY+Y0N4nT9pQ9drnt/ 8SGY/yJQ+yQlbGqL3R5ai9O/r1k2QqqZhn52L8PQSG0wqXLP2yI1G/4VSbN22U0QnIp1 YwfXWmBEuVUJTwy/Mwpkf/VnXhF+SIwRH2azLwpMNUtcbxCdKKXRI366p+ybpGLdRn0x oIug== 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:dkim-signature:dkim-signature; bh=sQse0ToDMpwewQdDE7yKhrAOT7WYcaPTU5OIWsPVcgM=; fh=Axll225WdqdQFQaL7hu+BChpyoSDalNUeY43I0NCcPM=; b=iw1N0YaILOBwSQB9Gw3OvkeajmBkzaeQYJnHMnPg4PNMFDtQh17zy+NTnSvSwxYTEM hgssBcsdUy/oFcjk8AtmKNHtBKGkEOn9BW3zZebm19/WZZdILATSg3wfoPkKdCs0BWUv SFtMrnLAknc75wSUZa/Dw2keOqJgjjdj90V478OYj+BiKNntIyWfcgQ8gwhhn3nTZv/Y tRP+1OmBg1+jQRzrEJPDDstKknWVWS+ufjkZ+puBjDdbWUDNbwYXg8bCLZqBHJ/vSBY7 AGWFnx6mEuPX+JHwaUnFAYWgHEc2BteLiyTYBnz5e+1TA7MLxv6UNCVWXPutV3b0BlmU 8Xig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OK+lbIcj; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n9-20020a170902e54900b001c3ffc982cfsi20886818plf.142.2023.09.28.16.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 16:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OK+lbIcj; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B06EC802FBBD; Thu, 28 Sep 2023 06:11:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbjI1NLi (ORCPT + 21 others); Thu, 28 Sep 2023 09:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231925AbjI1NLg (ORCPT ); Thu, 28 Sep 2023 09:11:36 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936DB180; Thu, 28 Sep 2023 06:11:34 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4D59421902; Thu, 28 Sep 2023 13:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695906692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sQse0ToDMpwewQdDE7yKhrAOT7WYcaPTU5OIWsPVcgM=; b=OK+lbIcjxBjHWwc61nh64vp9qLYNn8N2SPJO+Ljopy4iTIK7mKgtx745/r7gVy2fTnSy+w Cw5OHq+2UBwxYEDbu6AuetVyc4+0YGN3YXRHG6BQ7zstm+YHoXoIh1b0fFwlBrdK9bF0oy Lwv7fi58Dd5iRz0qJZ9ShzP08QhSktk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695906692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sQse0ToDMpwewQdDE7yKhrAOT7WYcaPTU5OIWsPVcgM=; b=GYulgtrzvdxvHTDJB7S8xKObEa1aO3wVm0XUj87rLNIekZVmjmpgy1T7euQnoqUlioP3Yq ggOVLLarlNLwIBCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D612A138E9; Thu, 28 Sep 2023 13:11:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wNI3MYN7FWW5ZgAAMHmgww (envelope-from ); Thu, 28 Sep 2023 13:11:31 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id cc60902a; Thu, 28 Sep 2023 13:11:31 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Alexander Viro , Christian Brauner , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?L?= =?utf-8?q?u=C3=ADs_Henriques?= Subject: [PATCH] fs: fix possible extra iput() in do_unlinkat() Date: Thu, 28 Sep 2023 14:11:29 +0100 Message-Id: <20230928131129.14961-1-lhenriques@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 06:11:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778291761136920261 X-GMAIL-MSGID: 1778327440986104319 Because inode is being initialised before checking if dentry is negative, and the ihold() is only done if the dentry is *not* negative, the cleanup code may end-up doing an extra iput() on that inode. Fixes: b18825a7c8e3 ("VFS: Put a small type field into struct dentry::d_flags") Signed-off-by: Luís Henriques --- Hi! I was going to also remove the 'if (inode)' before the 'iput(inode)', because 'iput()' already checks for NULL anyway. But since I probably wouldn't have caught this bug if it wasn't for that 'if', I decided to keep it there. But I can send v2 with that change too if you prefer. Cheers, -- Luís fs/namei.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 567ee547492b..156a570d7831 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4386,11 +4386,9 @@ int do_unlinkat(int dfd, struct filename *name) if (!IS_ERR(dentry)) { /* Why not before? Because we want correct error value */ - if (last.name[last.len]) + if (last.name[last.len] || d_is_negative(dentry)) goto slashes; inode = dentry->d_inode; - if (d_is_negative(dentry)) - goto slashes; ihold(inode); error = security_path_unlink(&path, dentry); if (error)