From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B22162D23A6 for ; Sat, 13 Jun 2026 15:20:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781364021; cv=none; b=RCjQphhl2o0dkyJT9TuHwWDfTuKxvHmvyT21+xW1lrax8JVEH6Y3QDTa0FonslDggBXotGmKwa9GbHjDy5czUMJ/mMshS389bdXp0n0IjnYMDrDeuonQZSbsCUvXujjePxJyBGEZkY07Ikua67YSGHxmCDpCWTV5T2bY2D9Em4Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781364021; c=relaxed/simple; bh=0tmlIj+AW4saUEYr6iZq6ttoIEdOF0dqz5pgiP7+iXc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=usVphbkYkpM64l/EnFvxC8zl+ZhAkVYck/3AEbPuOHNWeG67kZKk1nFwzcaMyMAa4cXQ6mByp91N18WU9C0CMPeU1Pd6ttAUsyV36cHQ3wP8W+zeydEdGPPgCpm3uMDy2WPsmY9xbj+gvh5QShgHmrZXKSudR5Bsk2tS4rEXZYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nv1ncjLK; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nv1ncjLK" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490c0c92cffso12743965e9.2 for ; Sat, 13 Jun 2026 08:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781364018; x=1781968818; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=PdUdJR3hjSlMBuPqq5j78SxOJ6CXwJNJeYAG6P57jTA=; b=Nv1ncjLKYf7ZH0lMjEe56xJtttiJCD4Tm24iFAjolZTsodfc9use1u2kME4HQtFqaW 9frOS8OocpCp5CIIt5rg63kEsN82eDR29USf5lobRSTqeKaqro2yI+iIdD5kOufazhoP gsHqrjrCf4KL1GPn5ZTihfMB4TPSXb8jeeoboejhJ1kV3n0CqysrhyV5DYHHEQE44CuZ pe1Yb7ZR47C05OYJGAj76jDQQyDSd6Dlv1UXmyGVHVEbtkNfpbJBThwpku+0e9kIbcpa atqWXp8xItdKFPIqXvYTLABklgsBLxBB/SnOgZHa6P3B6h8+ZgXpyytp1O8rNtCvqgjh ddoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781364018; x=1781968818; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PdUdJR3hjSlMBuPqq5j78SxOJ6CXwJNJeYAG6P57jTA=; b=NbjmeQXM2OcGga4y0z2R6lCdxzz8k5NPTLMIo9Oeqjt0eBaPVTj1Yxj9+fsmHslZFI RGnXWKR3s08BBkA5zTSPMZETZV9HpuhCey1lsj9PG/VwfWqoCyuFqMIeR4bwW3/Km+dI N405qRL7XDfB/oqci1rkuwa0EXrGIsQLN7M1eXWaw/thIBAKURfurrLDxFgkQ52eL+f1 IX4NhIVehqep5274AYhgLpgTkBtK4bqCpg8Ym+podaOr+zXFcAEUBgOZDM8Q/a4cVoXW 1SxEDQMKka62C7/yYbaT7kLUGGtRYpJ9QOzQTKCKJetnWGyHtggJzWJByExK9zAbO4wq JUIw== X-Forwarded-Encrypted: i=1; AFNElJ+bTt3bItrWyHXgyTrzRQb31JEdwEbbeGus1xLSvpYFI1lbvgH0bo55VoqCG0+M0i8khStVC+i9hm6FDdM=@vger.kernel.org X-Gm-Message-State: AOJu0YwZ0ciEFhvC1WtQCbtRCC/M2JE5tqytt6oYxQTUVCRd1FYfR/+k QpQ3QHlLyH2NhnMUT17DxZyO19i0ga7dydEuwZ1k5geJy6rOvsA+m00= X-Gm-Gg: Acq92OFCmd/SvmU63kU760o10dvzMLKvqg83a3AY0pF898Kj6LvANAVZ7/tZQ1tLXEu nbJfx2Dr4THWzXx8z+QwAfrc7+RSCsrZbpYAGy4otfcU4tAdYfIR3ox4u+wzGp0QiK69vxJZ/GH 4dvEyAhNoqwpgD6/D9Yg47TnyiZBLmNRQPsoNxwXnc1ee0Qd3PVSVbsYeT0LxHMrlVmCOozfcS3 Zu8RbLcVx+FwHKSMeQlYKg2EozXAFFJRuNBUGDf/M53YMdRomvCmTfm5eZFHEmcKSOf8rLt2H6c 6Kzjt+GObTt1Fk6cOIe3Q4D2gSg30Us131A/GcvrzO5UKQSSJB9SerZI302p6R8ZUcgOZ+whdJy dXLQ9Qf/8OG3Zh6j4EiI86mK+g9zq8iTFpWaw4sOc8LDzNt77fepU9CG1EKceAS2BHE1I8J3nyS mV4AM+kPgJ/MIMNEMBDCc1y1pyxDqCoA4JL0iznILeYYAIKAhGLltxzS9Qy+Nmc9VjEKqJ9eBMh cc= X-Received: by 2002:a05:600d:15a:20b0:490:bbc4:76a6 with SMTP id 5b1f17b1804b1-490ec4fb51fmr69260685e9.21.1781364017856; Sat, 13 Jun 2026 08:20:17 -0700 (PDT) Received: from p183 (dynamic-vpdn-brest-46-53-134-95.brest.telecom.by. [46.53.134.95]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4922031b7d2sm91066515e9.5.2026.06.13.08.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 08:20:16 -0700 (PDT) Date: Sat, 13 Jun 2026 18:23:09 +0300 From: Alexey Dobriyan To: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= Cc: Andrew Morton , Christian Brauner , Jan Kara , Wei Yang , Zijie Wang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] proc: only bump parent nlink when registering directories Message-ID: References: <20260612153031.536525-1-kwilczynski@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260612153031.536525-1-kwilczynski@kernel.org> On Fri, Jun 12, 2026 at 03:30:31PM +0000, Krzysztof Wilczyński wrote: > proc_register() increments the parent directory's link count for every > entry it registers, while remove_proc_entry() and remove_proc_subtree() > decrement it only when the removed entry is a directory. Regular files > thus inflate the parent's count while they exist, and leak one link > permanently on every create and remove cycle. > > For example, /proc/bus/pci/00 with twenty-two device files and no > subdirectories reports nlink 24 instead of 2, and SR-IOV VF enable > and disable cycles, each creating and removing the VF config space > entries under /proc/bus/pci/, inflate the link count of that > directory without bound. > > Before commit e06689bf5701 ("proc: change ->nlink under > proc_subdir_lock"), the increment lived in proc_mkdir_data() and > proc_create_mount_point(), and was therefore applied only to > directories. Moving it into proc_register() to bring it under > proc_subdir_lock dropped the S_ISDIR check. > > Thus, increment the parent link count only for directories, matching > the decrements in remove_proc_entry() and remove_proc_subtree(). > > Fixes: e06689bf5701 ("proc: change ->nlink under proc_subdir_lock") > Cc: stable@vger.kernel.org # v5.5+ > Signed-off-by: Krzysztof Wilczyński > --- a/fs/proc/generic.c > +++ b/fs/proc/generic.c > @@ -404,7 +404,8 @@ struct proc_dir_entry *proc_register(struct proc_dir_entry *dir, > write_unlock(&proc_subdir_lock); > goto out_free_inum; > } > - dir->nlink++; > + if (S_ISDIR(dp->mode)) > + dir->nlink++; > write_unlock(&proc_subdir_lock); nlink accounting should be folded into pde_subdir_insert/pde_erase probably but as minimal patch it's OK. Reviewed-by: Alexey Dobriyan