Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp782727ybl; Wed, 11 Dec 2019 07:27:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyArtScpfdqTQ3tMQBAmuvOZiN8+HzXkW/A7HlKd8VCangdiweF0rznW0qu5fzhCR/DQekp X-Received: by 2002:a05:6808:103:: with SMTP id b3mr3062608oie.89.1576078025681; Wed, 11 Dec 2019 07:27:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576078025; cv=none; d=google.com; s=arc-20160816; b=TdwEmpeuNAZdeAWx01nLOSorl9XsecmeMjqy6Fkmy22EYUJ3sXSvpbWi+xp5VeWFWJ YaS9NFTYPYNgk1qPzKZWPE02W6xUztkVReXcTt2rtbpJmgUYFaFmCS6Jc9vfMy4xo2/d Jw32+kuxG7ZuNlhZLaAu4ne2wmrQfIFaPfxxgpZfSowggNuTiYS84InW7y6aVIM5J/iL ODTRyoisdh1uEqmgOhDbc7lmfRC4hgkwbdzpg4YcguXvmiSvJyDI8tP2gwzqMDJyzyvN UfnhNqyjRQh/djaV6qHWY5jsxBfDwup3mJwgzFZsG3KrApHNoh5ZemEs0p13aTyArOiv P63Q== 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=xo4oo4azTxTWX7opZULaPXZLJlwF4yB9xNqDiHL1iBY=; b=qmBhG9L8a/36PWkws61Jler5C0mkfpKcI2xOvmuIp6YU1MMMNMNh/5iaLLVKVqhYK5 DRLiSfPkmLzee+6dmN9Ze8YAkSA1NFKOz2Z8jAC8av4/8DbO7G0dYHlbBTC7n9Oj5D/7 Re9ziUDkD7KB9BDBo4zd96uq3epqgZd6vIQczWOpSWuyYaVycfFpaSA4VnQ8rX0u39hG pBS+Q9GXodIhgyW+XsDb/kR+g14LGwpDcwjkQXRVzZm+QhL23byY0KC7U/eadAoLqvOI 5L0LmYggd2vSl2hED9Blil3TQSNhMf1d4PRLB/xoS/6JXWbyCq4qnMTk1Q5lDEeLrcxp oH4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JXms+b8; 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 d6si1233439otq.41.2019.12.11.07.26.53; Wed, 11 Dec 2019 07:27:05 -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=1JXms+b8; 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 S1732998AbfLKPZZ (ORCPT + 99 others); Wed, 11 Dec 2019 10:25:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:57284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732662AbfLKPZV (ORCPT ); Wed, 11 Dec 2019 10:25:21 -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 6168D208C3; Wed, 11 Dec 2019 15:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077920; bh=rOdz90QaNrmcTU1JSwFDpea1oaCw02rQheFZW9Px3q8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1JXms+b8NzeIcKBeso/hOfpETaCPEqX7Z1suq0XOcByYA3XJ9PPc2aVnaehrdY+5b x7Fb7XWxNuOZLA/+9Ldivwpl3daHQGOLIwisAEehHbUWMYdX05MeJjWcxqvAM08tJo GBwuEEl2AGHStfCOAj8DAThZXxn+UprkilApJ/bI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Namhyung Kim Subject: [PATCH 4.19 220/243] kernfs: fix ino wrap-around detection Date: Wed, 11 Dec 2019 16:06:22 +0100 Message-Id: <20191211150354.181459010@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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 @@ -624,7 +624,6 @@ static struct kernfs_node *__kernfs_new_ { struct kernfs_node *kn; u32 gen; - int cursor; int ret; name = kstrdup_const(name, GFP_KERNEL); @@ -637,11 +636,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 @@ -186,6 +186,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;