Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2313089imm; Mon, 28 May 2018 05:55:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZphRKSNiN2nso63pdMfZqU2Ty/qNf+AaiabCn15ejGE7B5cKsH1sXg6AWiDj9hZQMBXKwjU X-Received: by 2002:a63:8dca:: with SMTP id z193-v6mr10497395pgd.451.1527512128961; Mon, 28 May 2018 05:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527512128; cv=none; d=google.com; s=arc-20160816; b=UL2j4N73Jyov92zEea5Gj1emya5HS97YKwuDb4y7jhIl8r3v34LDOXPSlf4CB4JjGx Un3ddDtrVwjymxQ75791k53CSUvQxjlotDaTqF+sMrwXiAzY0FPZTnsfQsCKhDr2vil8 +Pe2n3v75HMVispd+7PMD8gTYeK1Ynlwc/3lM76so8L+26tcDLjzePYrHTeTkrjbs20r 9f9MOwdZttB/0BG/Usrzw+ZdNeieAovv26VBucAMtL7o6cKkF/qPgLejhzlqNomcIlJ3 WshUz17C+zU6Xd565yNoLrG8V5Cnsq0lXCI4vOQ2amCnlxZ8Ob56cZaCFQPNRKWv0xeb IjBw== 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-id:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :cc:to:from:arc-authentication-results; bh=nJV2ZL2+0uG+CX0oVyCUPJi/DDsmkIWQEWyVYyquOwQ=; b=0oH90p0HnyzzrgOm6KDxuRC2Bmsb3ypoDMKhDmvgzAonELsVjuzCnHwKJ4aE2gN3b2 dBz4j1JFYWqNYLsaeRGSe7Xr0R3CsLtCqh+UTtoWGR2tsra13DPvazaEzmoXfKOK/ESy LtgSwRNdEMK9lJ457Ar3tmQiAMnMH3T48GCscY4xxodq4D6+INOqgccv743zq5405T17 VgGf7g35fsQaBoveM5JfWIjK+3U8vwTZH8oTlFNKggrjlfXpx0hRK/pB9iSxPh8t7JnE gOnLfxC/HZk2XosVqkIHm8gyIy3l13d+FiOBb/yjlDMGVjJCuIbnA7z4wV07Q+R3iQZY 2GgQ== 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 e125-v6si30334075pfg.112.2018.05.28.05.55.14; Mon, 28 May 2018 05:55:28 -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 S1165069AbeE1My1 (ORCPT + 99 others); Mon, 28 May 2018 08:54:27 -0400 Received: from mgwym03.jp.fujitsu.com ([211.128.242.42]:60843 "EHLO mgwym03.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932508AbeE1MyM (ORCPT ); Mon, 28 May 2018 08:54:12 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym03.jp.fujitsu.com with smtp id 1e1b_218f_8fdf3253_d3e2_4791_bed5_c527d033c8f7; Mon, 28 May 2018 21:54:05 +0900 Received: from g01jpfmpwyt01.exch.g01.fujitsu.local (g01jpfmpwyt01.exch.g01.fujitsu.local [10.128.193.38]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 6E1E6AC01E5 for ; Mon, 28 May 2018 21:54:05 +0900 (JST) Received: from G01JPEXCHYT18.g01.fujitsu.local (G01JPEXCHYT18.g01.fujitsu.local [10.128.194.57]) by g01jpfmpwyt01.exch.g01.fujitsu.local (Postfix) with ESMTP id B2D186D66E4; Mon, 28 May 2018 21:54:04 +0900 (JST) Received: from G01JPEXMBYT03.g01.fujitsu.local ([10.128.194.67]) by g01jpexchyt18 ([10.128.194.57]) with mapi id 14.03.0352.000; Mon, 28 May 2018 21:54:04 +0900 From: "Hatayama, Daisuke" To: "'gregkh@linuxfoundation.org'" , "'tj@kernel.org'" CC: "Okajima, Toshiyuki" , "linux-kernel@vger.kernel.org" , "'ebiederm@aristanetworks.com'" Subject: [RESEND PATCH v2] kernfs: fix dentry unexpected skip Thread-Topic: [RESEND PATCH v2] kernfs: fix dentry unexpected skip Thread-Index: AdP2gtQcFftKX6rKRguW2o+iRXsAXg== Date: Mon, 28 May 2018 12:54:03 +0000 Message-ID: <33710E6CAA200E4583255F4FB666C4E21B63D491@G01JPEXMBYT03> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-TNEF-Correlator: received-spf: none (Could not find a valid SPF record ) x-securitypolicycheck: OK by SHieldMailChecker v2.5.2 x-shieldmailcheckerpolicyversion: FJ-ISEC-20170217-enc x-shieldmailcheckermailid: 8ec5e13069344ac1a10b2c754d90523a x-originating-ip: [10.124.136.24] Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <609F33E5C543104D8C3B28D054A93B0A@fujitsu.local> 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