From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9C42361670 for ; Wed, 24 Jun 2026 03:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782273547; cv=none; b=CpPMDU6Cw8S/DzBT50K6+p9F86/isZV24ndTPxdWVsif3eSH1irdvobXMWoMEEXvzMywiQ4jd6oKFmKjcpcO2wz53G9eDK6QnIaEec/vOgh/wGFS+3vhdUBuMMHwui9kNa2gHTDZRZcybHGvrWi+gLSH1snmaWQFcsnobahcDx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782273547; c=relaxed/simple; bh=WPUce5p8c2EUssWotG0cGhNLvcSMZmlN2FpDZaWBlEk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IJT+yot1RXde4qsuBdGimMHrBvoztFQ3oiK8O9IvsEYARm197gllxiYFWteLY3q/07sMI56RZGna6cg2jp170y4bofKQC/PRy4ut8//eBUZ2JsPFYEP/KeZO0jk+dKTSbajZGIEndPI2jZuminNYs1Zz+Awwdlza1KaEG1Xy4PM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DAmoJvwB; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DAmoJvwB" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-36ba706ab46so408757a91.1 for ; Tue, 23 Jun 2026 20:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782273545; x=1782878345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aijuYlDBKVQj7gxHHfn1uzpu7gtBUKO8JKuffLd7lBI=; b=DAmoJvwBfioZNUohy0ImiwAhVhDsMmrg6pdlxPOmPL9XSCZ5ubnP7fHnF4e87hk/TF sjcWNPrVGTv9Kd6IZr17nieR4xLK8tnNMFrBgRyKOmPBXFcLDBdOrrREUEHpl9F+A92l 9os3C5gk5aQDTsHLHwgDo+DIKqNHDM13jxWbE2kpHzqu+AjZBM/Re4kb1pHPL02bmBnP tG6XtzWsNr5tk5O+Ge5ucDesjiUW9t2FfezalWtcvcjj8wQvOids/w+nOM2YzuGCXi8L dX1gbZxuhtNO4nFNvh2oXH5jK4Rz096TJTFISRZcg+26PWnKIYI+Ph+HiQBreHijcd9s +1Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782273545; x=1782878345; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aijuYlDBKVQj7gxHHfn1uzpu7gtBUKO8JKuffLd7lBI=; b=JNvymjnVpJ1fRt2ZQdB1b8uQFEf5DJ5ZZGxnH3BvrCmBTIHTqDatBONuCPI3wsvhWY kIs7odMFmT1P47ZnOdoeD6WV6+a04h5zzV5CmKRS6N3kbIRKWUsk26ZYD0q1lQS0/5xC 5ZdU3Wo5zioSldl0BBDLY6nx0qji3iobXSCRXzFwuXYt4PvvpV7g66yRxBMBH6wMM2ZW zcMOtGY3e/UuodgMDaelgN9V9VpBOxzDkO+DA640E1N6+lWIOWpTN/x6wk4faiL2YMMl 3bmCukR0HTpfKX3idDj44Y45nGi/BAimaICGf7FJNYxCWduuADgvplj3DhtoL0VRYq7u fYdA== X-Forwarded-Encrypted: i=1; AHgh+RrYnUwEysRx5g+DCNewmKKQdIdyBo9oPZXLoBYj39pCr+UbWW5LAUivBP1RknbR+zhMZgdmsihfiEMaMrA=@vger.kernel.org X-Gm-Message-State: AOJu0YxDcKSyx6N4NHz6r2TKKhQpKoBAdjtMV9x8hRz8qAjsmgrDlGTf cnX3q48kCqM2Aj+Gdf4CUj9jilAI2dZKfPVtENXFLusaHrf3e8f0Un0n X-Gm-Gg: AfdE7cnyal2dQve9Ocf0+BUoO66kdzckfE08VvSeV0AHFHSctdwmFXcQ376LhfU8jbp 1Q/3ekctyj2Yh4q/f5e6U2oBvcOrIG1niSIgv2Kscd/ajYClDOKgPwr4xykr1UcO+7fpsIWf1LH 1D/Jygs41VdMqKTxH3R8sjFZNUrLS0s9ejhkdQXrR0/1MglvmNVEXG7+JI3VaMan/ZRkoq7kYuj sgZpKsnU3XXH/tb3prqMlwIJxYlebvqtv8roNBdY2zyfHF5XjzqYNNdZZ/gr/H6cTI8gXzEL5Q8 IebV0e8JADxmmdiXsGpNWjrRTkANakhn5qPe4c9DTnSWHcBdxybLXf1PqCJ9K9kyD7quZTJ/yS9 n3iBqj9/5htlnADHtSL3+6b8iUueGswnCEcanrYmrmDt5QlatihihXkJjPLmdU0eMegJMezntGU wg0qHpfWQn86UJegvA+Amo9RBYL6WaiHec X-Received: by 2002:a17:903:244b:b0:2b4:59bf:5728 with SMTP id d9443c01a7336-2c7e14ea7e2mr17342975ad.25.1782273544995; Tue, 23 Jun 2026 20:59:04 -0700 (PDT) Received: from haichao.tail057a43.ts.net ([2001:da8:e000:1206:69f4:9671:af22:eb44]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c742fdd411sm135555715ad.0.2026.06.23.20.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 20:59:04 -0700 (PDT) From: Ruoyu Wang To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Ruoyu Wang Subject: [PATCH] NFSv4: remove callback IDR entry on client allocation failure Date: Wed, 24 Jun 2026 11:58:58 +0800 Message-ID: <20260624035858.172129-1-ruoyuw560@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit nfs4_alloc_client() allocates an NFSv4.0 callback identifier before it finishes setting up the client. If any later initialization step fails, the error path frees the nfs_client directly with nfs_free_client(). That bypasses nfs_put_client(), which is where the callback IDR entry is removed during normal teardown. A failed allocation can therefore leave cb_ident_idr pointing at a freed nfs_client. A later NFSv4.0 callback lookup by cb_ident would find the stale pointer and take a reference to it. Make the callback IDR removal helper callable by the allocation failure path, and remove the callback identifier before freeing the client. This was found by a local static-analysis checker for publish-before-free lifetime bugs and confirmed by manual inspection. Fixes: f4eecd5da342 ("NFS implement v4.0 callback_ident") Signed-off-by: Ruoyu Wang --- fs/nfs/client.c | 14 +++++++++++++- fs/nfs/internal.h | 1 + fs/nfs/nfs4client.c | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 4dcb91ab..60386330 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -215,9 +215,21 @@ static void nfs_cb_idr_remove_locked(struct nfs_client *clp) { struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); - if (clp->cl_cb_ident) + if (clp->cl_cb_ident) { idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); + clp->cl_cb_ident = 0; + } +} + +void nfs_cb_idr_remove(struct nfs_client *clp) +{ + struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); + + spin_lock(&nn->nfs_client_lock); + nfs_cb_idr_remove_locked(clp); + spin_unlock(&nn->nfs_client_lock); } +EXPORT_SYMBOL_GPL(nfs_cb_idr_remove); static void pnfs_init_server(struct nfs_server *server) { diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index acaeff7d..a9b3023d 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -225,6 +225,7 @@ void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); extern void nfs_put_client(struct nfs_client *); extern void nfs_free_client(struct nfs_client *); +void nfs_cb_idr_remove(struct nfs_client *clp); extern struct nfs_client *nfs4_find_client_ident(struct net *, int); extern struct nfs_client * nfs4_find_client_sessionid(struct net *, const struct sockaddr *, diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 71c271a1..aff019d2 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c @@ -261,6 +261,7 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) return clp; error: + nfs_cb_idr_remove(clp); nfs_free_client(clp); return ERR_PTR(err); } -- 2.51.0