From patchwork Tue Apr 23 10:26:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13639720 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5611A605CE; Tue, 23 Apr 2024 10:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713867994; cv=none; b=ChBXz6zZU8MLa2tdQZjVNKeSiP07vL38MF2c1TneWWAACv6aA1M+jSPheUzBQVLAoK/kRTDtz+ziuo1qdg9tblYFyPZqDABcVPqunNhSjtKasLCj6UN0sGg1+RweGlbyLTZ5NgH5HrshNzipuuc4/xlMgcXiZSKUZ8sCBkIIfIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713867994; c=relaxed/simple; bh=4J1adAuX9oXH34Y3qG9TeINgYulPL2SQPOywb4uFuKg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CDoSHq/p7dlEp91RMx4ZmmKNYZuop7x9oziMln2oTwqrv2BvIuyPzfvYh5HogtvhZEtswhaUgCIs89aEBKBYHY4n42UI8C1+zc79YCsyMZYAyLRLni54IhPNilftdLlfx1lCdkRWyZNobU+sBmBis4RpOBDo4TBxkLHRDiexoTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ToceAe+y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ToceAe+y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71102C3277B; Tue, 23 Apr 2024 10:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713867993; bh=4J1adAuX9oXH34Y3qG9TeINgYulPL2SQPOywb4uFuKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ToceAe+yRZnryawNFUR2E+7Lf3E/QEvSzaomX8NALTrgRqPjm3Q1FER6Q7ytpt5A4 w/SmW/RmwWtba8c050o5zh8zge1VRqcP/4E7ieM4F9IhHsf2z7rEq7JGqW00VlIaIH yNQtMuNXe+KULd2pLIC99OqU1IkHhzi4vKY/0qiVmerQ2iU/jpZ8np4lNz+c//u1Fi xuCYT3duIb+SBGsQhihOJ2rDChv+OgL/AA5DrDJhrV472qz1A2KK8qudu6O49IRoOD /hlrg6ZVs8mZbEesZ75SGewui1ctxvurcdwleNaNswdwr+9SEi4K1IKDvKmn5EjFHt /SMuH7y5B7OFw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jakub Sitnicki Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Geliang Tang Subject: [PATCH bpf-next v5 1/2] selftests/bpf: Check recv lengths in test_sockmap Date: Tue, 23 Apr 2024 18:26:14 +0800 Message-Id: <0de8cc53c7b797fbb8d8a12748b30353ca99d98d.1713867615.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The values of recv and recvp in msg_loop may be negative, so it's necessary to check if they are positive before using them. Fixes: 16962b2404ac ("bpf: sockmap, add selftests") Fixes: 753fb2ee0934 ("bpf: sockmap, add msg_peek tests to test_sockmap") Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- tools/testing/selftests/bpf/test_sockmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 43612de44fbf..24b55da9d4af 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -680,7 +680,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, } } - s->bytes_recvd += recv; + if (recv > 0) + s->bytes_recvd += recv; if (opt->check_recved_len && s->bytes_recvd > total_bytes) { errno = EMSGSIZE; @@ -694,12 +695,14 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, iov_length * cnt : iov_length * iov_count; - errno = msg_verify_data(&msg, recv, chunk_sz); - if (errno) { - perror("data verify msg failed"); - goto out_errno; + if (recv > 0) { + errno = msg_verify_data(&msg, recv, chunk_sz); + if (errno) { + perror("data verify msg failed"); + goto out_errno; + } } - if (recvp) { + if (recvp > 0) { errno = msg_verify_data(&msg_peek, recvp, chunk_sz); From patchwork Tue Apr 23 10:26:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13639721 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0D033481D1; Tue, 23 Apr 2024 10:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868001; cv=none; b=bw40MsIfDrnTyuiAP1CyOEB+Votsfqilw/jWcQAn4nsKIcKJAxO8rHdhfW4cmL0DnGVq0sj+ku3JEwhl/VjaUQYTm+W3DXR3Rfo38jKb+0JJnTEOJtuNfO/cisRCN8OciXXk5B1gCA1LckdffmEoKs9zMU4jLKmwwBimiouvc3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868001; c=relaxed/simple; bh=9HXfbycHwqXmAKZDBEaimP6Gs01ML6b9Mr8ArWmc5sQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ihDPcAgaJw4cjsCldSd3vUjZdERQi/YeZxy28FN+Ni8uO3+qKe/Q8QIuee5Sk47Ue9jwIlSD4q5aEd9if9w11lk1dhxNE5QEapP1xL2/kt0oj3WFC9EAHqTGZ2GayX56K8aea33agHF9uDpoIbrV77mXgbGQlDHX2+j758cRzxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HUdLp2va; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HUdLp2va" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 774B8C4AF07; Tue, 23 Apr 2024 10:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713868000; bh=9HXfbycHwqXmAKZDBEaimP6Gs01ML6b9Mr8ArWmc5sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUdLp2vaosudp7Vptnmtwg5Ie6CPqqDyiXrxwr4ei1WvKFkt/KHpebM0ko69cABJ/ 14pO38LaEWhNxj1IDyIfM0hRrVvbZ4FzTsT8aBGznxVkcFJrseCtaZASBtvdKJIlUq ZQjvmftlADtj98EDR3b7y07R38pE35wEopy2T11KoIYWhLbgaZ2iN56B0LJZlEyjoJ NSOUZYMfXWV1yqkDHGHlXEn6PTrPV9uK211ysKehmlUwxt+m5lTO5Q6Hy3y8Al5d++ Fd4Hd4+e+e/QlGjXoJ0UWDl/BSqPyWORQ2qUTJckNZWoiFsnA24a7BV5+w6v5/9c7/ JR5xuPtGF+pCA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jakub Sitnicki Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Geliang Tang Subject: [PATCH bpf-next v5 2/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap Date: Tue, 23 Apr 2024 18:26:15 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Incorrect arguments are passed to fcntl() in test_sockmap.c when invoking it to set file status flags. If O_NONBLOCK is used as 2nd argument and passed into fcntl, -EINVAL will be returned (See do_fcntl() in fs/fcntl.c). The correct approach is to use F_SETFL as 2nd argument, and O_NONBLOCK as 3rd one. Fixes: 16962b2404ac ("bpf: sockmap, add selftests") Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- tools/testing/selftests/bpf/test_sockmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 24b55da9d4af..74a2c6e74fae 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -603,7 +603,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, struct timeval timeout; fd_set w; - fcntl(fd, fd_flags); + if (fcntl(fd, F_SETFL, fd_flags)) + goto out_errno; + /* Account for pop bytes noting each iteration of apply will * call msg_pop_data helper so we need to account for this * by calculating the number of apply iterations. Note user