Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2730936pxb; Mon, 17 Jan 2022 04:45:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5/75BxI+IMmW5JMV7MyO3NwWTis1nUZy0BprtoSpCwu74+1xcqgy8u8i7or2QCgDozK9s X-Received: by 2002:a17:90b:3e82:: with SMTP id rj2mr13570366pjb.35.1642423557432; Mon, 17 Jan 2022 04:45:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642423557; cv=none; d=google.com; s=arc-20160816; b=EKsmgDTKf8ku68F3Zrrqnrof3EzETMs2l49Bk0ioiYJzshz5RPK9+CooM5rxAZAB05 eTlMAhuGKgK/CJY5wWO7gLp2diNJZQY7106sniXx41+Qv4Oc3gCq7Q8h4G+IwQtsbDvC oGXbZFI8Un3h95wTcDD12G0vc4L76WiW+oPVADPbhc5gBex/nfAFWUyBLhKZYaw5faVT Kx9uoEiF9G0G4N+FAmiHzkIQFjMX6aqZprMtzGcdAfEMvsf5hB5gRLCHPzHW9vVLQXi2 OdYkp+NrJYOQNIN4KwWvDosAWm6L3D5nfQ3W/JGyeI2LXmxjy4QY2YHSfDhFBiEfwD/8 5BXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:mime-version :content-transfer-encoding:dkim-signature:dkim-signature; bh=IXWqcj6mgh2grqkHruNd87w8lgUweF5/uQAMw17Tiaw=; b=LdiaDEFQ9A/S5eq9ggMkR8mz43QA7JA5eoBAIb7hu66Lv2+Y1mAs6aruoI7XpLglxY VfVFNvM0iP6T9Nfgcbueu2lprCywP7RDtDLEaPzccPnX9skWlzk/4llzcZR3TxAJ2bTU ccsHVkU/uLoQ3UkSFhT7gdmXb7BxSITmoq4Zm71oqDeZ/RgMGogCPqxKe5kH3V5tXor6 uVQPx2VTsJdhv8/Nro0tDkYjKYrAA9Z+NHz84HP+4fbEidUVaKSk3zFn7jzYCtbGIDIh PqeZkiUT3GbJeTkw4HAbB6xb9zGG06TjhC6xunFyBvE70Xpiqsb2MMSEQkST5F1PxBgH ci4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="c11E/8iK"; dkim=neutral (no key) header.i=@suse.de header.b=Lmru8IZ5; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h16si12816223plf.480.2022.01.17.04.45.35; Mon, 17 Jan 2022 04:45:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="c11E/8iK"; dkim=neutral (no key) header.i=@suse.de header.b=Lmru8IZ5; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231936AbiAQFcX (ORCPT + 99 others); Mon, 17 Jan 2022 00:32:23 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:49860 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbiAQFcW (ORCPT ); Mon, 17 Jan 2022 00:32:22 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8B76F212C4; Mon, 17 Jan 2022 05:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642397541; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IXWqcj6mgh2grqkHruNd87w8lgUweF5/uQAMw17Tiaw=; b=c11E/8iK8+Xv+MPv8rjEmVlY4vYgjcsR92j09Qpzuj/6XoduoZrTndS5LzBX/sQNgUHPur wzLiQx5/TnQG/08Pd1Rpte9hGHmWNSf+ytnpWgVUhgx+mlXGPFP9vyUXHNYVcKRH/HYHdc ltjtGUW2u7rw5QCpgH3zX1X5AS8gkIM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642397541; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IXWqcj6mgh2grqkHruNd87w8lgUweF5/uQAMw17Tiaw=; b=Lmru8IZ5FMyhtSY4IRdhf+NzEBQHIiK/S45yQQUYk+BabMHkkZD1cLtyYXFpNlQa+gE7ss OPnx4HTjFElJdvCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 715F1134AD; Mon, 17 Jan 2022 05:32:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SoScC2T/5GFAXgAAMHmgww (envelope-from ); Mon, 17 Jan 2022 05:32:20 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: Anna Schumaker , 'Trond Myklebust' Cc: Linux NFS Mailing List Subject: [PATCH] SUNRPC: lock against ->sock changing during sysfs read Date: Mon, 17 Jan 2022 16:32:16 +1100 Message-id: <164239753694.24166.6067045930030508953@noble.neil.brown.name> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org ->sock can be set to NULL asynchronously unless ->recv_mutex is held. So it is important to hold that mutex. Otherwise a sysfs read can trigger an oops. Commit 17f09d3f619a ("SUNRPC: Check if the xprt is connected before handling sysfs reads") appears to attempt to fix this problem, but it only narrows the race window. Fixes: 17f09d3f619a ("SUNRPC: Check if the xprt is connected before handling = sysfs reads") Fixes: a8482488a7d6 ("SUNRPC query transport's source port") Signed-off-by: NeilBrown --- net/sunrpc/xprtsock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 9d34c71004fa..3f2b766e9f82 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -1641,7 +1641,12 @@ static int xs_get_srcport(struct sock_xprt *transport) unsigned short get_srcport(struct rpc_xprt *xprt) { struct sock_xprt *sock =3D container_of(xprt, struct sock_xprt, xprt); - return xs_sock_getport(sock->sock); + unsigned short ret =3D 0; + mutex_lock(&sock->recv_mutex); + if (sock->sock) + ret =3D xs_sock_getport(sock->sock); + mutex_unlock(&sock->recv_mutex); + return ret; } EXPORT_SYMBOL(get_srcport); =20 --=20 2.34.1