Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp872307ybl; Wed, 11 Dec 2019 08:47:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzeGEajVfTJk+A3vDgMC7W7TngqVr4zy7taFA9zgBGfdnNKcq2jBq0S1jlXq8QkOhZE5XPP X-Received: by 2002:a54:450e:: with SMTP id l14mr3439191oil.36.1576082867680; Wed, 11 Dec 2019 08:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576082867; cv=none; d=google.com; s=arc-20160816; b=jlxVRVzTYFmQx0HIqMF0bMsxPq+Ehv0rACB2PiZC9e/eNLgoD5YkgTTX/H0osWB4CW omtuD2BkeMrKc85+Relw39w22Wi2H2Pgu0QDnTVARiEWRA1F0qq8cgwN1TxKafwTBOfc oyQGEZEP1xcMlYty4SgpUOSH8ym/hnclCxduokwkqISnoNnvUqwLhy3szWWxbsrvLo12 GiqQvWLSnZrhv1NhgJCP5HXAvBIexlJ/+Z0KXurMh3M608HxX2tPNLwuivr8+QJJYpuh xBFwcX8zT3vB3UfMLHiiHSUrnBW9Uv8wGvhA4bDGfBldzu38sYGFxJrMoyR/gYu59QU6 x+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qTmfaP5yj31p9+0tKN/CZwwvUj+716bP3uPq3KlhGDg=; b=waudmyp0Vxo82Ox6Oe+GMVu7TTPRyof9Hks32q+FezJ9h1d3yJfFeuGmlHdpXqFyt+ UNW48U3KK8/oHuV92C1LtiS6ir4m2R3TRWw2Rx4cXigQtE9nMqOXSUDlAp2XM2hJs2gd 390WH9lScZf68PdKhuXntnEcRUVu3LwXfU/EsGgyEaGrJ97MY/3M26DgXkZLpjYZBgsq rvNiGGMBm8KA6IckpV2N04/hr309QOcbKcsvQou16PCnaDdWSdoKzzxknUTp2ivChoko s1Nl4uie8YTpIvZUJuOOgdqUq4IfZDAWncTAOEgJq1PSDNSNcMoaO83EdlEx3VUO7txc xI5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jaWiyXHh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r21si1454157otd.276.2019.12.11.08.47.35; Wed, 11 Dec 2019 08:47:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jaWiyXHh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731882AbfLKP73 (ORCPT + 99 others); Wed, 11 Dec 2019 10:59:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:38584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731561AbfLKPOD (ORCPT ); Wed, 11 Dec 2019 10:14:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F050520663; Wed, 11 Dec 2019 15:14:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077242; bh=Ha7dnqnrqOkOuSjrc0UfdUtJMrE/DtnEIbdDGy/SvBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jaWiyXHhqzM9LhWkI7AdJnd81YjuP9U3J4l3/ZlQ5jBGmC70Y3DrpuEISLQoiXXSu DdT1c2CnvVOnf0senUeTibeh+Vcq/wUWzwPIZXgGHP3JPdEaMKQzLQR2vjZTPYXIs/ 3jvhjLlwsIN+9vLuGxhxuL57ek28ZUArNnpcSV60= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Namhyung Kim Subject: [PATCH 5.3 070/105] kernfs: fix ino wrap-around detection Date: Wed, 11 Dec 2019 16:05:59 +0100 Message-Id: <20191211150250.877112320@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo commit e23f568aa63f64cd6b355094224cc9356c0f696b upstream. When the 32bit ino wraps around, kernfs increments the generation number to distinguish reused ino instances. The wrap-around detection tests whether the allocated ino is lower than what the cursor but the cursor is pointing to the next ino to allocate so the condition never triggers. Fix it by remembering the last ino and comparing against that. Signed-off-by: Tejun Heo Reviewed-by: Greg Kroah-Hartman Fixes: 4a3ef68acacf ("kernfs: implement i_generation") Cc: Namhyung Kim Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Greg Kroah-Hartman --- fs/kernfs/dir.c | 5 ++--- include/linux/kernfs.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -621,7 +621,6 @@ static struct kernfs_node *__kernfs_new_ { struct kernfs_node *kn; u32 gen; - int cursor; int ret; name = kstrdup_const(name, GFP_KERNEL); @@ -634,11 +633,11 @@ static struct kernfs_node *__kernfs_new_ idr_preload(GFP_KERNEL); spin_lock(&kernfs_idr_lock); - cursor = idr_get_cursor(&root->ino_idr); ret = idr_alloc_cyclic(&root->ino_idr, kn, 1, 0, GFP_ATOMIC); - if (ret >= 0 && ret < cursor) + if (ret >= 0 && ret < root->last_ino) root->next_generation++; gen = root->next_generation; + root->last_ino = ret; spin_unlock(&kernfs_idr_lock); idr_preload_end(); if (ret < 0) --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -187,6 +187,7 @@ struct kernfs_root { /* private fields, do not use outside kernfs proper */ struct idr ino_idr; + u32 last_ino; u32 next_generation; struct kernfs_syscall_ops *syscall_ops;