Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp313192qtb; Wed, 19 Oct 2022 02:36:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4A7V6V0IrP0jmfYWvTJh99CjcDj8T9URGVsR1427vtc+eRtch73AzKSRRz6QyEgqbPsnxM X-Received: by 2002:a05:6a00:16c4:b0:535:890:d52 with SMTP id l4-20020a056a0016c400b0053508900d52mr7793532pfc.9.1666172205390; Wed, 19 Oct 2022 02:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172205; cv=none; d=google.com; s=arc-20160816; b=YRUwkXKZeWWlx9E1lkCFPRDNnhP6HaTk5Rhnp2RrGQaQMNYaxqPcClVHyGmEJdie2B 0D52eA/Wf0FS3au9JBwhrbPl+fCKw+lMQBKDwW6A35+/svRtQ/+dQE+co6P1ULBHyfDO 8l4uN6Gun9jqGCAApCaSx1n9joXEFPfuVj9xShHLHrp9ckbqZocJaJe1KrDQWQTCxOzK vCHeNNBx3H9X5yR9fHiv7Aw9yw430MMunHYG4vcFnjhm7g59DiiWsxKoI+Bg/Q8uBmm7 Qk5qpdAFHDVkIzOjmwggzTzC/VVSVJyz6VN0A6dzyiq2oGCma6oLG7eAsuNRPP5xxjl9 wFKA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g18-20020a63e612000000b0045b0a113f6asi18579819pgh.846.2022.10.19.02.36.32; Wed, 19 Oct 2022 02:36:45 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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)