From patchwork Mon Jan 13 08:52:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Liu X-Patchwork-Id: 13936939 X-Patchwork-Delegate: kuba@kernel.org Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E26E231C85; Mon, 13 Jan 2025 08:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758401; cv=none; b=hLRc838hqhmA2gP6CgwiP3fR+8WkLuOqCajEbUHa6tvb8E3O+kzFx+MB3WxOFKn/f5THnf+LqnOMjQ/+3aWbUypJGOk3cDLonD+WOB96mW+Gfk8c/fZ6VUUsdlyKQuj/wAqmhdErZj6GHaJS6bF2WsvdhUUSe8Ie0WwbMq41gQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758401; c=relaxed/simple; bh=RWEeHfG9BQkArbMKfBgICdcmFhIRztEGenKMQAmHmPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q3wBlD7Ji9fExLZeCjIUybA4cOyaVYs5FeYfe1psBx1J+bADIZdNp0QyIxuj0YSqxSrNfkEjT7Jfgp6MC93EXSMVYV2afQY6zmHliDsEoiaNAeRMFBhUNPfVgjo2xrm66W+q6cBamoUdi4WaBsz4tgwr0NBgiOwLpaxXZqi2xRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: c788b560d18b11efa216b1d71e6e1362-20250113 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_DIGIT_LEN HR_FROM_NAME, HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT HR_TO_DOMAIN_COUNT, HR_TO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED SA_EXISTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:fc02180d-d521-490e-9457-56c73f22c610,IP:15, URL:0,TC:0,Content:0,EDM:-30,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-24 X-CID-INFO: VERSION:1.1.45,REQID:fc02180d-d521-490e-9457-56c73f22c610,IP:15,UR L:0,TC:0,Content:0,EDM:-30,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-24 X-CID-META: VersionHash:6493067,CLOUDID:47ea4b778172c04fb58a60f0be9d93df,BulkI D:250113165257UAMC824I,BulkQuantity:1,Recheck:0,SF:17|19|24|38|45|66|78|81 |82|102,TC:nil,Content:0|50,EDM:2,IP:-2,URL:0,File:nil,RT:nil,Bulk:43,QS:n il,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC :0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: c788b560d18b11efa216b1d71e6e1362-20250113 X-User: liucong2@kylinos.cn Received: from liucong.. [(116.128.244.171)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1324680574; Mon, 13 Jan 2025 16:52:55 +0800 From: Cong Liu To: Matthieu Baerts , Mat Martineau , Geliang Tang , "'David S . Miller'" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Cong Liu , netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] selftests: mptcp: Fix incorrect file descriptor check in main_loop Date: Mon, 13 Jan 2025 16:52:26 +0800 Message-ID: <20250113085228.121778-2-liucong2@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113085228.121778-1-liucong2@kylinos.cn> References: <20250113085228.121778-1-liucong2@kylinos.cn> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Fix a bug where the code was checking the wrong file descriptor when opening the input file. The code was checking 'fd' instead of 'fd_in', which could lead to incorrect error handling. Signed-off-by: Cong Liu --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index 4209b9569039..31f4c5618569 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -1249,7 +1249,7 @@ int main_loop(void) if (cfg_input && cfg_sockopt_types.mptfo) { fd_in = open(cfg_input, O_RDONLY); - if (fd < 0) + if (fd_in < 0) xerror("can't open %s:%d", cfg_input, errno); } @@ -1272,7 +1272,7 @@ int main_loop(void) if (cfg_input && !cfg_sockopt_types.mptfo) { fd_in = open(cfg_input, O_RDONLY); - if (fd < 0) + if (fd_in < 0) xerror("can't open %s:%d", cfg_input, errno); } From patchwork Mon Jan 13 08:52:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Liu X-Patchwork-Id: 13936938 X-Patchwork-Delegate: kuba@kernel.org Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27F1D19341F; Mon, 13 Jan 2025 08:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758399; cv=none; b=mtzqHkySdXz8TGfLDrmpUWvgKy69oj/iDel/mfJyzsHEAq+U5Ql377NhOGnC9/+0SiCv1xQZh2yM6TCLl8KmFyjQYJolIRSk59y9PPztGF66Huvq1NrVPjAHgfYrupAB9jy732B28bTALhY4mrsRC3TBwrA89yH+2BF6XuSumO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758399; c=relaxed/simple; bh=+kYpJ/KVCG2w+X4rMMgBTQbw+Rnog2FhHOywqZR6VLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u5DppW6r0IU+2S3sBnbRVtuiWzq0q/ZKST29XXNVILeGx2rTt8i31rKH0R+U2Fq1iZZlyZTTHTi9rF2DBkOVZpzUapwykwMfhVN8Pw8gVvyC6D+MBcRkhlDYdPTUXpzU4LrvUI2VuaOlwtXPVsSECJ2U7SLm/nx6i59K8zfpxiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: c7e4e5c4d18b11efa216b1d71e6e1362-20250113 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_DIGIT_LEN HR_FROM_NAME, HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT HR_TO_DOMAIN_COUNT, HR_TO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED SA_EXISTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO GTI_C_BU, AMN_T1, AMN_GOOD, AMN_C_TI, AMN_C_BU ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:3b6df243-79cf-496c-9ad1-556d10a3544e,IP:15, URL:0,TC:0,Content:0,EDM:-30,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-24 X-CID-INFO: VERSION:1.1.45,REQID:3b6df243-79cf-496c-9ad1-556d10a3544e,IP:15,UR L:0,TC:0,Content:0,EDM:-30,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-24 X-CID-META: VersionHash:6493067,CLOUDID:ef8c3a63588174d54e3754e1ba308b18,BulkI D:2501131652574KZ42GSN,BulkQuantity:0,Recheck:0,SF:17|19|24|38|45|66|78|81 |82|102,TC:nil,Content:0|50,EDM:2,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS: nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,AR C:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: c7e4e5c4d18b11efa216b1d71e6e1362-20250113 X-User: liucong2@kylinos.cn Received: from liucong.. [(116.128.244.171)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 989990396; Mon, 13 Jan 2025 16:52:55 +0800 From: Cong Liu To: Matthieu Baerts , Mat Martineau , Geliang Tang , "'David S . Miller'" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Cong Liu , netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] selftests: mptcp: Fix input fd lifecycle in reconnection loop Date: Mon, 13 Jan 2025 16:52:27 +0800 Message-ID: <20250113085228.121778-3-liucong2@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113085228.121778-1-liucong2@kylinos.cn> References: <20250113085228.121778-1-liucong2@kylinos.cn> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When both cfg_input and cfg_sockopt_types.mptfo are set, the input file descriptor (fd_in) is opened before the reconnection loop but closed within the loop. However, when mptfo is enabled, the descriptor is not reopened in the loop, causing subsequent iterations to use an invalid file descriptor. Move the file open operation into the loop to ensure fd_in is always valid when needed, regardless of mptfo setting. Signed-off-by: Cong Liu --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index 31f4c5618569..4d4ea4627daa 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -1247,12 +1247,6 @@ int main_loop(void) struct addrinfo *peer; struct wstate winfo; - if (cfg_input && cfg_sockopt_types.mptfo) { - fd_in = open(cfg_input, O_RDONLY); - if (fd_in < 0) - xerror("can't open %s:%d", cfg_input, errno); - } - memset(&winfo, 0, sizeof(winfo)); fd = sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, fd_in, &winfo); if (fd < 0) @@ -1270,7 +1264,7 @@ int main_loop(void) if (cfg_cmsg_types.cmsg_enabled) apply_cmsg_types(fd, &cfg_cmsg_types); - if (cfg_input && !cfg_sockopt_types.mptfo) { + if (cfg_input) { fd_in = open(cfg_input, O_RDONLY); if (fd_in < 0) xerror("can't open %s:%d", cfg_input, errno); From patchwork Mon Jan 13 08:52:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Liu X-Patchwork-Id: 13936941 X-Patchwork-Delegate: kuba@kernel.org Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6E46232392; Mon, 13 Jan 2025 08:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758409; cv=none; b=uuDS1HG//mCnFjIBT/fH9Esy1h80qtO9ZcfstguWugNT2MlXm6ZZvE6aPrr3Co4UfeKKMSKz6GGzK61D66ots8zBpWdlTl8t1bk3Y30qoTEOw57Psb6gOWp4LMhExWsFaLxGWxso7m0TcOCt/SG/nuXRezO0/R8L6x7lZ2FvPFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758409; c=relaxed/simple; bh=SK4jnUxCfO5MkjZkyyhmQQ3cVcdvn0wTiQADlt7lpJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHllZYy0MHxoNUdHmSRo417B/hwFY6cv3QRXkWfIAEAMIAc2agb+VepFgQU7RJZQfWbouQHsj7LwmIzMcexGoV/S6fTy3nFgQoJO7+dAQVIA+3qwhPiKtUYsRIAeRUIzKG3zosFVnBi82PG5T6yB7ZlToCl2uWDTpSGCjguf1DA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: ccb78a16d18b11efa216b1d71e6e1362-20250113 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_DIGIT_LEN HR_FROM_NAME, HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT HR_TO_DOMAIN_COUNT, HR_TO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED SA_EXISTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:97cfeb80-4387-4d39-8760-5ae6d7a00303,IP:15, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:6 X-CID-INFO: VERSION:1.1.45,REQID:97cfeb80-4387-4d39-8760-5ae6d7a00303,IP:15,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:6 X-CID-META: VersionHash:6493067,CLOUDID:fd31e4db36654752146d2299e5270fdb,BulkI D:25011316530690BTK29T,BulkQuantity:0,Recheck:0,SF:17|19|24|38|45|66|78|81 |82|102,TC:nil,Content:0|50,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS :nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,A RC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-UUID: ccb78a16d18b11efa216b1d71e6e1362-20250113 X-User: liucong2@kylinos.cn Received: from liucong.. [(116.128.244.171)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1690955869; Mon, 13 Jan 2025 16:53:03 +0800 From: Cong Liu To: Matthieu Baerts , Mat Martineau , Geliang Tang , "'David S . Miller'" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Cong Liu , netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] selftests: mptcp: Clean up resources properly in main_loop Date: Mon, 13 Jan 2025 16:52:28 +0800 Message-ID: <20250113085228.121778-4-liucong2@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113085228.121778-1-liucong2@kylinos.cn> References: <20250113085228.121778-1-liucong2@kylinos.cn> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add proper cleanup of resources (file descriptors and address info) in error paths to prevent resource leaks. Signed-off-by: Cong Liu --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index 4d4ea4627daa..e82fde0411b2 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -1271,8 +1271,13 @@ int main_loop(void) } ret = copyfd_io(fd_in, fd, 1, 0, &winfo); - if (ret) + if (ret) { + close(fd); + if (cfg_input) + close(fd_in); + freeaddrinfo(peer); return ret; + } if (cfg_truncate > 0) { xdisconnect(fd, peer->ai_addrlen); @@ -1291,6 +1296,7 @@ int main_loop(void) goto again; } else { close(fd); + freeaddrinfo(peer); } return 0;