Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3220843rdh; Thu, 28 Sep 2023 06:15:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnIExxQ7r2RhgAHWVELlcvDE5vx8cQec2OWPJzs9hL2GkZLct/d3kMTiXDx8t2v/uc1KSw X-Received: by 2002:a17:902:8205:b0:1c3:3c91:61cc with SMTP id x5-20020a170902820500b001c33c9161ccmr894984pln.13.1695906900415; Thu, 28 Sep 2023 06:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695906900; cv=none; d=google.com; s=arc-20160816; b=p/fSNy9ngP68o0z6SmbrXtkHTxmcTHG8D1w4w9scQfcexOT3NTZ2EArzyHY9kkxaXQ mwDyrYAR8do+p2Fk3mZ7tbpiQgXrgoD8upf8f72JS/2znIZX1aCs3uw50TizDNDSNB/n 56kMAsuLcBWq3WbVdBqTHgGyeol2b/SkB1Vjs58OVbeP+BPzTBTza51CIaKBaB5n9Fmp FZHGZI8mRJeL46eJKW0LIwGO/uN3w9aYQVQdKakbkzLnvK72a+nmSsLJIs69yQDYlo1q cS+RucWHpW3K4iMVifGc8QDU+13jFCiQOQIAVnsxM4oCx4mwSQJFSiSGj80ClsdLTIs3 9H8g== 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 header.b=GYulgtrz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l12-20020a170903244c00b001c474ff2fdesi20530450pls.378.2023.09.28.06.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:15:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; 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 header.b=GYulgtrz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 1C8508054B44; Thu, 28 Sep 2023 06:11:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232672AbjI1NLh (ORCPT + 99 others); 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=20Henriques?= To: Alexander Viro , Christian Brauner , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Lu=C3=ADs=20Henriques?= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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]); Thu, 28 Sep 2023 06:11:47 -0700 (PDT) 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)