Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp60427imm; Mon, 21 May 2018 02:11:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUISAjBjQc7tiXdpBryc6TDaRDg9sG98FyHqaXRBm6HUqfnwmdzeSvGwEp6hkge4Y/VvD2 X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr19073927plq.215.1526893916660; Mon, 21 May 2018 02:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526893916; cv=none; d=google.com; s=arc-20160816; b=HNiAhUnNgERSIkzMBofXCsDEM/go2iwB+WzgJr1zdmAESibwOZ2sSC5766Slg3y8ja S25Jd+iWo7Ql8lAy8p9qDdmRItnSCfm3SAXDr88vcZmp953qsnHibCiwteuuuJM8+jbR b5KoMyeMJKF8iD2aFcm0T1ZdiNTc6r3scFylVBgM6MltnJ2Ckw6eaEOtKWRlQpDsO+FD HFT4tIgfITkRQUnxvqoOyzzVrYS3uXDE5BjW+tPiipf2TWgf/aq/elxGKXmRxzRhD/M7 d7AnsHNVsLBrYzF2eQ55Z7/+S9iWBGTtuSJcxS+biv6OdsMAfH4zZI7NNGg4990Ax/X9 pgsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :cc:to:from:arc-authentication-results; bh=nJV2ZL2+0uG+CX0oVyCUPJi/DDsmkIWQEWyVYyquOwQ=; b=WLx8qv9m6Is/r4cw2Den9CEvIuJHdNP2P9Gbubsj1Y90wwFis5GA5JSPl2XhFObTrJ QDQeHL3jka2DOQ2BJLXaiVnC7UuKqr2MKuf8hpV0w/LcHrktw/6O4mlZoBic7wJ8gwA2 LJDwOixxy6XmSWPUQ/ziNYHa1Y3hbkuSktqY3DWCm9ABA18Dwr+1HkVbAfQzX2CaAS5t PlTfgkZYgyLvDNiP3if69AAXVBer3ConGLVD67HpPdvJ9I1g1weUAGkB4jwEvTWvABhP l6BmIdFPJ3yM4ajnR0A5lRhjOyfoO/d51CTBNID//U+6EYPDDuDcHufMTloCdO5xiMMd VV+A== ARC-Authentication-Results: i=1; mx.google.com; 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 v10-v6si14416918plz.190.2018.05.21.02.11.42; Mon, 21 May 2018 02:11:56 -0700 (PDT) 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; 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 S1751111AbeEUJLe (ORCPT + 99 others); Mon, 21 May 2018 05:11:34 -0400 Received: from mgwkm04.jp.fujitsu.com ([202.219.69.171]:57869 "EHLO mgwkm04.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922AbeEUJLd (ORCPT ); Mon, 21 May 2018 05:11:33 -0400 Received: from kw-mxoi1.gw.nic.fujitsu.com (unknown [192.168.231.131]) by mgwkm04.jp.fujitsu.com with smtp id 4332_18b0_f73a1f4c_51e3_4540_b5d5_839af7b2eb6e; Mon, 21 May 2018 18:11:29 +0900 Received: from g01jpfmpwyt02.exch.g01.fujitsu.local (g01jpfmpwyt02.exch.g01.fujitsu.local [10.128.193.56]) by kw-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 12889AC0102 for ; Mon, 21 May 2018 18:11:29 +0900 (JST) Received: from G01JPEXCHYT15.g01.fujitsu.local (G01JPEXCHYT15.g01.fujitsu.local [10.128.194.54]) by g01jpfmpwyt02.exch.g01.fujitsu.local (Postfix) with ESMTP id 49B2158428E; Mon, 21 May 2018 18:11:28 +0900 (JST) Received: from G01JPEXMBYT03.g01.fujitsu.local ([10.128.194.67]) by G01JPEXCHYT15 ([10.128.194.54]) with mapi id 14.03.0352.000; Mon, 21 May 2018 18:11:28 +0900 From: "Hatayama, Daisuke" To: "'gregkh@linuxfoundation.org'" CC: "Okajima, Toshiyuki" , "linux-kernel@vger.kernel.org" , "'ebiederm@aristanetworks.com'" Subject: [PATCH v2] kernfs: fix dentry unexpected skip Thread-Topic: [PATCH v2] kernfs: fix dentry unexpected skip Thread-Index: AdPw42U/Kv0zQJrKRmGIT81k9ZZiyw== Date: Mon, 21 May 2018 09:11:26 +0000 Message-ID: <33710E6CAA200E4583255F4FB666C4E21B5E60C5@G01JPEXMBYT03> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-securitypolicycheck: OK by SHieldMailChecker v2.5.2 x-shieldmailcheckerpolicyversion: FJ-ISEC-20170217-enc x-shieldmailcheckermailid: 1921b80fd642497b92e7c1385f6e50ae x-originating-ip: [10.124.89.120] Content-Type: text/plain; charset="iso-2022-jp" MIME-Version: 1.0 X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kernfs_dir_next_pos() overlooks the situation that the dentry corresponding to a given pos object has already been inactive. Hence, when kernfs_dir_pos() returns the dentry with a hash value larger than the original one, kernfs_dir_next_pos() returns the dentry next to the one returned by kernfs_dir_pos(). As a result, the dentry returned by kernfs_dir_pos() is skipped. To fix this issue, try to find a next node only when the returned object is less than or equal to the original one. Note that this implementation focuses on getting guarantee that the existing nodes are never skipped, not interested in the other nodes that are added or removed during the process. We found this issue during a stress test that repeatedly reads /sys/module directory to get a list of the currently loaded kernel modules while repeatedly loading and unloading kernel modules simultaneously. v2: Fix the case where nodes with the same hash but with the name larger than the original node could still be skipped. Use kernfs_sd_compare() to compare kernfs_node objects. Imporove patch description. Signed-off-by: HATAYAMA Daisuke Suggested-by: Toshiyuki Okajima Cc: Eric W. Biederman --- fs/kernfs/dir.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 89d1dc1..3aeeb7a 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -1621,8 +1621,10 @@ static int kernfs_dir_fop_release(struct inode *inode, struct file *filp) static struct kernfs_node *kernfs_dir_next_pos(const void *ns, struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos) { + struct kernfs_node *orig = pos; + pos = kernfs_dir_pos(ns, parent, ino, pos); - if (pos) { + if (pos && kernfs_sd_compare(pos, orig) <= 0) { do { struct rb_node *node = rb_next(&pos->rb); if (!node) -- 1.7.1