From patchwork Tue Jul 5 04:55:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1652229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=pPmaAHUD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LcVlV4B6dz9s1l for ; Tue, 5 Jul 2022 14:57:10 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1o8acS-0008Kd-Bd; Tue, 05 Jul 2022 04:57:04 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1o8acQ-0008Ga-7s for kernel-team@lists.ubuntu.com; Tue, 05 Jul 2022 04:57:02 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id EC9A93F838 for ; Tue, 5 Jul 2022 04:57:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1656997021; bh=uOJ66rzdZj+N7lYy+qNKeCdfu+4UDYGuxLwflfWNaYE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pPmaAHUDw7H6G9ZmaBvdIdr7M6SALH5aA/Oohgvt3DuXrLWekakQxY133xFzr86CR 8Hq53OETW6cGbx2Ir47vJm0riHzpeuIveZIDdjsu/QxbgK+i4QBOv6EWj1pZn1ZfAc ZSK3MoZHS/r6foZBlgjKzOVbJuL8ZdYAdXjoacWqOlFe/qIdmD3hCbjhi90/qKUc6M DwsqN+GerBkHtLRMAashat3strCvEFNapFN53dY0kfiiYlkWwxapUNuZC1DJ+yNnoJ IrHV4c9zL1a3c3i5T3l4iQjBk9C/+byA737zPwDjgCZ7ys0W17mZa3dMwu7kS1WOZA OH65dxAonAnZw== Received: by mail-ej1-f70.google.com with SMTP id hs18-20020a1709073e9200b0072a3e7eb0beso2301963ejc.10 for ; Mon, 04 Jul 2022 21:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uOJ66rzdZj+N7lYy+qNKeCdfu+4UDYGuxLwflfWNaYE=; b=4EiOCut5h/0GYzqQKWFcxEIG30372DPg+4U0Kwy269YSY88eXtU9EQlnbkarQUhhFE bt0dyDyXqRziocE9Y8WdsLdhM3A1GCwjVBWzeJY9XHgDFTkoc7TdNC2Mp+19uk9I229x oSAeDBFeNHOq+wEX9Ddu//dWlw05htGJ5cKHgl0xU5Lh53MA3UFbhVLf2gs+8Ythzja1 8XoqiohmsA2kbGeD3nWHvS7qo25AVm18KNb7nWJeJFrCnz3cO0wPxwgmXcCOC/Qklq47 LYXxe4lbsEnNTOgjS4o3nWab0uz2+3Wq91p8wFR9KAttMwTL/tpiFKyUA77c0M2xc7Z3 aKlg== X-Gm-Message-State: AJIora/SM61N0xT/gnkw1w6ZyuC/6XttsOiCjNo/u0dEb7t1W7GQaKLM IHOaYv5lS9JI2Zh33uR0D9A2n1YrBH9CGXcozIjFRxI0apb04FiyVh9D2xGvBC5VDAFtNcLKK6j h3n8Sb17ughKeUQ/jQlB+1UTOc6xzoF2dgG3/zcdMkA== X-Received: by 2002:a05:6402:35d6:b0:435:9f33:3363 with SMTP id z22-20020a05640235d600b004359f333363mr44306385edc.349.1656997020868; Mon, 04 Jul 2022 21:57:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sFJxlceBXNUH4CfOKG1IDcmitopJKXeZ3ZBUGLvW6+v9U/uWbwGOFA+3OlyVAEpbM3+NUNEA== X-Received: by 2002:a05:6402:35d6:b0:435:9f33:3363 with SMTP id z22-20020a05640235d600b004359f333363mr44306360edc.349.1656997020627; Mon, 04 Jul 2022 21:57:00 -0700 (PDT) Received: from localhost ([46.2.184.254]) by smtp.gmail.com with ESMTPSA id kt26-20020a170906aada00b00726dbb18b59sm9378782ejb.130.2022.07.04.21.57.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 21:57:00 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH v2 2/2] SUNRPC: Don't leak sockets in xs_local_connect() Date: Tue, 5 Jul 2022 07:55:48 +0300 Message-Id: <20220705045549.274705-3-cengiz.can@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220705045549.274705-1-cengiz.can@canonical.com> References: <20220705045549.274705-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Trond Myklebust If there is still a closed socket associated with the transport, then we need to trigger an autoclose before we can set up a new connection. Reported-by: wanghai (M) Fixes: f00432063db1 ("SUNRPC: Ensure we flush any closed sockets before xs_xprt_free()") Signed-off-by: Trond Myklebust CVE-2022-28893 (backported from commit aad41a7d7cf6c6fa804c872a2480f8e541da37cf) [cengizcan: we don't have commit c4f0396688b5 which fixes the indent issue so change context] Signed-off-by: Cengiz Can --- net/sunrpc/xprtsock.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index af4b12ff1d6f6..47df2cbc9175b 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2063,6 +2063,9 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task) struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); int ret; + if (transport->file) + goto force_disconnect; + if (RPC_IS_ASYNC(task)) { /* * We want the AF_LOCAL connect to be resolved in the @@ -2075,11 +2078,17 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task) */ task->tk_rpc_status = -ENOTCONN; rpc_exit(task, -ENOTCONN); - return; + goto out_wake; } ret = xs_local_setup_socket(transport); if (ret && !RPC_IS_SOFTCONN(task)) msleep_interruptible(15000); + return; +force_disconnect: + xprt_force_disconnect(xprt); +out_wake: + xprt_clear_connecting(xprt); + xprt_wake_pending_tasks(xprt, -ENOTCONN); } #if IS_ENABLED(CONFIG_SUNRPC_SWAP)