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: 13402987 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 C4B43E732CC for ; Thu, 28 Sep 2023 13:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbjI1NLh (ORCPT ); Thu, 28 Sep 2023 09:11:37 -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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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)