Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp1261945qtg; Thu, 30 Mar 2023 11:29:32 -0700 (PDT) X-Google-Smtp-Source: AKy350a+mjIGZrXSJoJn+1/gXwWUFinTv9rm1vYodnhHvOsDuPkLI7F76He8sSJ3v3wMrViW7Pmv X-Received: by 2002:a62:7905:0:b0:627:ef8d:117a with SMTP id u5-20020a627905000000b00627ef8d117amr23667948pfc.15.1680200972310; Thu, 30 Mar 2023 11:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680200972; cv=none; d=google.com; s=arc-20160816; b=hx1lWAlHHGZ7883Mt4QembXvu2bEgm4kf93JXm4Og+riYqPRWj4HmiknFuNB+edQCn kTFwW4Pjh2VmM62fd4fK5JL3mgdyNZ867OqC035bgpehdXU1t+EGHdvGGhrTMRd0UMlA I/MHIQB8glIEsHWDvz5kziSKpmNASKz+UM3ISk6uEc62gsLsGOpMhJ1gyaVIsvRnTQc+ vcGEcOKViZWjW4md9NgH5bvWn3Y5+HRpl25vcUEMxFyGutmjsSkaKuqtfKdTDbmnJiWW n+mxlDguow/wOHcPV8/CmUhchLZ1BdeZQglM6u/Si5i+LF3Em9OgSjb72mZ9w1KY4rGq sI3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dqBLXVy+GnCxLMRU1Ni/Cu/fcj4BSVZV3voadrqIvC8=; b=0Z8Zdok022fcO3iEdEmEPlkIxcp4ptJB6OMYaRU8oUoUEuOgzguEii8cDuJ8QL20CK BiVYd3DuV/TYE2ci9xwRejQOKWYs6NmgiyJkQ9hdoygt9g1+ppyE5//Rx/H7zGk6TvWy 2lROJwoWrr/FECbmnqGNhMnuQGZ67EfdfdJWhf4ZIF7pHiRgEh8GAepscFuZOentWR3k X+dpjqrvgt6EXPhuR/RrVQjkUiqT5Rr0L9UrN97Nt27UZy1gjA6CKqtr0r4gh8lvVp9T fvMhN3f8DPzR+qpPO3b/zU0vz5crpHFqf4p+lWhiP5hp4K8PLprGqRbpOUi0gsp+xgzB KXJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nOsZpSs9; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a636401000000b0050f6ab16eedsi219980pgb.688.2023.03.30.11.29.02; Thu, 30 Mar 2023 11:29:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nOsZpSs9; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjC3SYb (ORCPT + 99 others); Thu, 30 Mar 2023 14:24:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjC3SYa (ORCPT ); Thu, 30 Mar 2023 14:24:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E95265FEB for ; Thu, 30 Mar 2023 11:24:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8150062096 for ; Thu, 30 Mar 2023 18:24:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C71DC433D2; Thu, 30 Mar 2023 18:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680200668; bh=3USdfrjb5l7xlmDJ8ohzbDcPg5hh5psnp5u7gqpUa9U=; h=From:To:Cc:Subject:Date:From; b=nOsZpSs9M30qu21sbMlA6vGPU+zCYki3dl1vflO7+rgJyIz0zJBwHQUINLWHtiBAL pnMdrpZz0NQxssv58IYRKIg5/4sWICdk90kK/ZWrgH7ES6vsyDD0AKa/2ikYhKRbGe ULGCwBkN0VusM465Xo7rk/S1iBfG1qHkDpPOMk7rzARQqZT1uqiHSmpHpdwwgTRSSD sPS+YqR92wrEoWoYMDGhVa4FiSOKn3cf3OzFkNL2DQbWzI8LDBFWmLjgmHoK5gkMyk MWlIvvhXY7uAkJ07XyC/e1VMQlFyaMGnDg+Xo1Z5zHMvf7gMcqhpYP6LDE0BqNfZsu iUMClE3aDPWHA== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org, bcodding@redhat.com, Zhi Li Subject: [PATCH] sunrpc: only free unix grouplist after RCU settles Date: Thu, 30 Mar 2023 14:24:27 -0400 Message-Id: <20230330182427.19013-1-jlayton@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org While the unix_gid object is rcu-freed, the group_info list that it contains is not. Ensure that we only put the group list reference once we are really freeing the unix_gid object. Reported-by: Zhi Li Link: https://bugzilla.redhat.com/show_bug.cgi?id=2183056 Signed-off-by: Jeff Layton --- net/sunrpc/svcauth_unix.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 50e2eb579194..4485088ce27b 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -416,14 +416,23 @@ static int unix_gid_hash(kuid_t uid) return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS); } -static void unix_gid_put(struct kref *kref) +static void unix_gid_free(struct rcu_head *rcu) { - struct cache_head *item = container_of(kref, struct cache_head, ref); - struct unix_gid *ug = container_of(item, struct unix_gid, h); + struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu); + struct cache_head *item = &ug->h; + if (test_bit(CACHE_VALID, &item->flags) && !test_bit(CACHE_NEGATIVE, &item->flags)) put_group_info(ug->gi); - kfree_rcu(ug, rcu); + kfree(ug); +} + +static void unix_gid_put(struct kref *kref) +{ + struct cache_head *item = container_of(kref, struct cache_head, ref); + struct unix_gid *ug = container_of(item, struct unix_gid, h); + + call_rcu(&ug->rcu, unix_gid_free); } static int unix_gid_match(struct cache_head *corig, struct cache_head *cnew) -- 2.39.2