Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2143928pxb; Fri, 25 Mar 2022 11:52:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU9H2rif/LHz+ZB+AJxP1fGF1cPR1tJgxlQhwqY70bWqnPI+qUHAW4gS0iS9nf9rL0Hh5h X-Received: by 2002:a65:63d8:0:b0:380:2be6:806a with SMTP id n24-20020a6563d8000000b003802be6806amr780778pgv.20.1648234370578; Fri, 25 Mar 2022 11:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648234370; cv=none; d=google.com; s=arc-20160816; b=sw1irS5v6iZwUyxaKmMZC6/2FfhXa5O1MgW0HrG0jp+jxC9xzhVfE02gQiq7SdaJUt 4yorGaJjr70iGN7Gb8iEOQCInUi6QiIVl+aSpCjyJ/+lGIF7FhZ8BsFNJC9bT9/4YmWI eUDLKwVxajsnS4gBjPe9omPm+uve4gs7NwUH2PtFWv0N9xp2cyyecCUuOySlCmgWpWR8 8SJoq4qoRQvMi425ZJsiuZ37LZWbggVNfK50gxD3Y97KeRUbNVFQpP1cCIY1xVoxhhI7 FZl1xb0HzcJ/9AU0H1sRooAustXpMESlzOdcG1uaSUQbWqQt6xghfuzOxm+2E0ZI3AUq DeMg== 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:to:from:dkim-signature; bh=AYLR+q6hfHM+vFfK6e/uGAVlJwxD7QG2RblVBqlH814=; b=ptI15DInKLSgosHUSCuX6O3eyDsZJUQNx6UuDrHD1r5u0xx6KSat7l4EMIKw438mnk PGlziIZC6UqJHlk/upC+r2oz4RDAMiRjF2frZoxr56tIFm/sJjoInSqxvWAALXyKyuj8 ilwgcJVfMoNAwlx/NhdZIM/poZggu4osm2a4S5SzPqYBE/v5k73FOCHOJoTRBo0p9NFT 0dYqTowomXmok8eH/MPEb7voRx+3pTyiG38yHCariCJAzMh5pO2OKtNbFRNW/y5pPtkr LYAAZY5o1xqrWR+bLUmZ213Pp0bZ0HArReBPLke/YcC6Dh8F0L1k/8jSO7GC343xHnfw O/oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YfB+4YJ0; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u12-20020a056a00124c00b004fa5a577b93si3599413pfi.51.2022.03.25.11.52.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YfB+4YJ0; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 377751BE4C1; Fri, 25 Mar 2022 11:05:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352459AbiCXVl1 (ORCPT + 99 others); Thu, 24 Mar 2022 17:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349593AbiCXVl0 (ORCPT ); Thu, 24 Mar 2022 17:41:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 473B564BE5 for ; Thu, 24 Mar 2022 14:39:54 -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 ams.source.kernel.org (Postfix) with ESMTPS id D4AAAB82649 for ; Thu, 24 Mar 2022 21:39:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54DDEC340EC for ; Thu, 24 Mar 2022 21:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648157991; bh=rix6ZfMLXe62BFLdDMPJ/Nhi6jVLo5mSerSc1Ys1UQk=; h=From:To:Subject:Date:From; b=YfB+4YJ0BDWR/pf5zQw5vL1bZHBxayr8AvQ+FKEVcYMemjOrEBOnNMtrzdj1fl/qh MXMMmmoLmFP96p68VHXBEBvjX8KBaVQZ2rtn23umJ7f8npg1iufmRiimiPXlk3lMtj y8enscaWnOfiVqIbU1eaffIoef7sgoPaHY1bqTND2JHCzBOuNzaYw4ddVNOze80Nuj 063nPhMaYyDeN5PH882OMmNrP3pSoJw0XkMW0+2phOfxdmGam4b1zZCcLauTzH5TXZ fMyKUBDDKNYY1UD6ng0FFNu2zTDZFcESQeaGHig6OI8GNl2SzgMNsgy35t9COlOw2a D6UD0nHx+tD9w== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] SUNRPC: Do not dereference non-socket transports in sysfs Date: Thu, 24 Mar 2022 17:33:44 -0400 Message-Id: <20220324213345.5833-1-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Trond Myklebust Do not cast the struct xprt to a sock_xprt unless we know it is a UDP or TCP transport. Otherwise the call to lock the mutex will scribble over whatever structure is actually there. This has been seen to cause hard system lockups when the underlying transport was RDMA. Fixes: e44773daf851 ("SUNRPC: Add srcaddr as a file in sysfs") Cc: stable@vger.kernel.org Signed-off-by: Trond Myklebust --- net/sunrpc/sysfs.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 05c758da6a92..8ce053f84421 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -107,22 +107,34 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); struct sockaddr_storage saddr; struct sock_xprt *sock; + const char *fmt = "\n"; ssize_t ret = -1; - if (!xprt || !xprt_connected(xprt)) { - xprt_put(xprt); - return -ENOTCONN; - } + if (!xprt || !xprt_connected(xprt)) + goto out; - sock = container_of(xprt, struct sock_xprt, xprt); - mutex_lock(&sock->recv_mutex); - if (sock->sock == NULL || - kernel_getsockname(sock->sock, (struct sockaddr *)&saddr) < 0) + switch (xprt->xprt_class->ident) { + case XPRT_TRANSPORT_UDP: + case XPRT_TRANSPORT_TCP: + break; + default: + fmt = "\n"; goto out; + }; - ret = sprintf(buf, "%pISc\n", &saddr); -out: + sock = container_of(xprt, struct sock_xprt, xprt); + mutex_lock(&sock->recv_mutex); + if (sock->sock != NULL) { + ret = kernel_getsockname(sock->sock, (struct sockaddr *)&saddr); + if (ret >= 0) { + ret = sprintf(buf, "%pISc\n", &saddr); + fmt = NULL; + } + } mutex_unlock(&sock->recv_mutex); +out: + if (fmt) + ret = sprintf(buf, fmt); xprt_put(xprt); return ret + 1; } -- 2.35.1