From patchwork Wed Oct 19 08:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp202222wrs; Wed, 19 Oct 2022 01:40:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7XFt8e4w5kI0NVupalqXB5c8aNPinJqpDAUronMrsGO+f63Aux6POJjxaf6pn6v+LFhd5a X-Received: by 2002:a17:906:4fca:b0:78d:b042:eeca with SMTP id i10-20020a1709064fca00b0078db042eecamr5612750ejw.685.1666168812384; Wed, 19 Oct 2022 01:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168812; cv=none; d=google.com; s=arc-20160816; b=lRT3ZI0wp3gflI4CEtxWrF5/vn+Dn/LSQj9RU67288Kl7Gn/iM+mJQowGUH3KuWQ3I DQWqUftRbB8B08xhaPSt453puETtpOKlS2vpNnsrO3EbcBpYEiyAEnezC39dIbqyp69I myB7WO/e612+xygmqE+5hgZDd0q9xWPBe6HX+aoWsOjBPpTYPmodjGnm52BDVGUVr0QT oS6/rjIr7RxqJUksXT7jpdD60Kq3IvhDOGCFlyy0fbduEQUNYWvUgzhUxfH68YsSzmpP d95HRy3dZKs5RYF4dTZF5LLZWZUvRPHZYt+jolg6TRYd8ZQI709vpxDsSDgq8SRD9TB+ uufw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MoIGUngN6xxiQPS47laFp8Spogpof+Yt4rVgTTA/yQM=; b=dVJvkNlutMDoWPNm9zXXRBz1UuLVJE+yWbtP3uZs+hBrSnL05JMtz6fLivlWEZ/zm7 5vdapg34DjWxWW8cZfreHGBS8+O8Oxpnrig56uGqxVCuu450f3AbNmK3sTA7cNmZuQYp VEyCnD9RXCpFQG8gqAMRTRy3Q7Xfjm6oqN6pS1fOJKGUe6mVB9PoDdAGwrQRX02bV21g FRYw9yoPtt2xgrSupYGnuGiV+CFnbEAbCcpWS9tcEVlOphTXpLhfl4m24zF9y8uUO9rz DhJWNjLa3eX8odSD8zJQktxN4VoTFtja/7t+y0vkfCqsgcUo3cop6J9+0yQsp0OvBPk5 UUag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NkIYhfVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di10-20020a170906730a00b0078d51aa5967si16237436ejc.944.2022.10.19.01.39.47; Wed, 19 Oct 2022 01:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=NkIYhfVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbiJSIjU (ORCPT + 99 others); Wed, 19 Oct 2022 04:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbiJSIik (ORCPT ); Wed, 19 Oct 2022 04:38:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38EB38112C; Wed, 19 Oct 2022 01:38:15 -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 A9C17617AC; Wed, 19 Oct 2022 08:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4B48C43470; Wed, 19 Oct 2022 08:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168676; bh=72hmIiOc3TIOnfmh7t6u3JsBy/1wx4DTVUeW+p9gm0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NkIYhfVfVbR4TXah9qmoTWoVzVSwPzhX66EG4VzNFPVJLWdTWeWtQ/EUsvMvdua2L 8eRg/iObNtg6PyzwieHahfyICEf24dugIFleWN/wj25Iycw663CmGRYtbDOE7mDoqV eIT2oJNCciQL5NutZWqCSq2W3443JEot21O/oBYg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aidan Sun , Jens Axboe Subject: [PATCH 6.0 018/862] io_uring/net: handle -EINPROGRESS correct for IORING_OP_CONNECT Date: Wed, 19 Oct 2022 10:21:45 +0200 Message-Id: <20221019083250.812246178@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104628426570766?= X-GMAIL-MSGID: =?utf-8?q?1747104628426570766?= From: Jens Axboe commit 3fb1bd68817288729179444caf1fd5c5c4d2d65d upstream. We treat EINPROGRESS like EAGAIN, but if we're retrying post getting EINPROGRESS, then we just need to check the socket for errors and terminate the request. This was exposed on a bluetooth connection request which ends up taking a while and hitting EINPROGRESS, and yields a CQE result of -EBADFD because we're retrying a connect on a socket that is now connected. Cc: stable@vger.kernel.org Fixes: 87f80d623c6c ("io_uring: handle connect -EINPROGRESS like -EAGAIN") Link: https://github.com/axboe/liburing/issues/671 Reported-by: Aidan Sun Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- io_uring/net.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) --- a/io_uring/net.c +++ b/io_uring/net.c @@ -46,6 +46,7 @@ struct io_connect { struct file *file; struct sockaddr __user *addr; int addr_len; + bool in_progress; }; struct io_sr_msg { @@ -1263,6 +1264,7 @@ int io_connect_prep(struct io_kiocb *req conn->addr = u64_to_user_ptr(READ_ONCE(sqe->addr)); conn->addr_len = READ_ONCE(sqe->addr2); + conn->in_progress = false; return 0; } @@ -1274,6 +1276,16 @@ int io_connect(struct io_kiocb *req, uns int ret; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; + if (connect->in_progress) { + struct socket *socket; + + ret = -ENOTSOCK; + socket = sock_from_file(req->file); + if (socket) + ret = sock_error(socket->sk); + goto out; + } + if (req_has_async_data(req)) { io = req->async_data; } else { @@ -1290,13 +1302,17 @@ int io_connect(struct io_kiocb *req, uns ret = __sys_connect_file(req->file, &io->address, connect->addr_len, file_flags); if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) { - if (req_has_async_data(req)) - return -EAGAIN; - if (io_alloc_async_data(req)) { - ret = -ENOMEM; - goto out; + if (ret == -EINPROGRESS) { + connect->in_progress = true; + } else { + if (req_has_async_data(req)) + return -EAGAIN; + if (io_alloc_async_data(req)) { + ret = -ENOMEM; + goto out; + } + memcpy(req->async_data, &__io, sizeof(__io)); } - memcpy(req->async_data, &__io, sizeof(__io)); return -EAGAIN; } if (ret == -ERESTARTSYS)