From nobody Sun Dec 14 19:12:29 2025 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 2196216C683; Fri, 10 May 2024 09:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335105; cv=none; b=Wn5yPqQIeVItlZVusp+qbPPQ+DkUtpXzACC1uDPbBJzvwaqUHUiFUhS4mhDPKTtTOcZA1SpgwwruyNObSMJnoRv1J+RoFMmYW6tyWtxoUGDYDG2SniWs4mSfgGfiaCvxGEDAaoyTFBDNX1gP97wERhlQinVcIvzO1b+rv0LWvYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335105; c=relaxed/simple; bh=L5CtxcTyFe4ed4Z4V5GzUmwGAj4pyd/5Gw6Sce0wkyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dXvkHuYObMySZmvQq3Nz+xN0sXY2TH52OGiHTIMzYbZE7e/FuPz3ZgKkDm3dKDSdeYgWEB6ZWnRuN6qSmSmLlqW1w7k9XR6fy5xMwRvxVL2rQHtHDharQJ50zxX+gMzdpSfqgME8Fnkpr8tWUpZHYIxkN1CzyHxiCT8R/JOSp+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xdMCXLkx; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xdMCXLkx" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715335102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W1C/72k3CZqrqQ8uzPc/VTP/P/Rw9MPoSpFvH6FC94M=; b=xdMCXLkxAwQR7/Rdu0KQ0aeqzSuPHIOOG5MO2qG3rrkiN72687KX/wrY8xYgwC3U7ZKFuY y0ex++vSNlf6eryLU9R4t9tWEz3Stbhxuw8ZjCKMMKu4pOxjVLSlzPak0+D9AqYFkC1Ems TpeYjO8C7XU9a3P9vy4GAXD0XUvYofE= From: kunwu.chan@linux.dev To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, kunwu.chan@hotmail.com Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks Date: Fri, 10 May 2024 17:58:00 +0800 Message-Id: <20240510095803.472840-2-kunwu.chan@linux.dev> In-Reply-To: <20240510095803.472840-1-kunwu.chan@linux.dev> References: <20240510095803.472840-1-kunwu.chan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan There is a 'malloc' call, which can be unsuccessful. This patch will add the malloc failure checking to avoid possible null dereference. Signed-off-by: Kunwu Chan --- tools/testing/selftests/bpf/test_progs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selft= ests/bpf/test_progs.c index 89ff704e9dad..ecc3ddeceeeb 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -582,6 +582,11 @@ int compare_stack_ips(int smap_fd, int amap_fd, int st= ack_trace_len) =20 val_buf1 =3D malloc(stack_trace_len); val_buf2 =3D malloc(stack_trace_len); + if (!val_buf1 || !val_buf2) { + err =3D -ENOMEM; + goto out; + } + cur_key_p =3D NULL; next_key_p =3D &key; while (bpf_map_get_next_key(smap_fd, cur_key_p, next_key_p) =3D=3D 0) { @@ -1197,6 +1202,8 @@ static int dispatch_thread_send_subtests(int sock_fd,= struct test_state *state) int subtest_num =3D state->subtest_num; =20 state->subtest_states =3D malloc(subtest_num * sizeof(*subtest_state)); + if (!state->subtest_states) + return -ENOMEM; =20 for (int i =3D 0; i < subtest_num; i++) { subtest_state =3D &state->subtest_states[i]; --=20 2.40.1 From nobody Sun Dec 14 19:12:29 2025 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 7776816D4C6 for ; Fri, 10 May 2024 09:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335109; cv=none; b=GM3Ynyshuv3kTfki9S7/HJp8EuhXdezA4GpuGS1TKOp2wzBDXrUpmipeJzAngaScaQz1lJq44gHAGJ9rnyqMUS+zInZvNBJSU96s20MIdDfGyAprtP9SplD8F96e0Sc6Aokfx2ECdR2CFhx8OEuv5+1ZrgvSSds1F1QQSg0KM48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335109; c=relaxed/simple; bh=z9zdge8Uw/xViOY7Q1RU4YYXc81cHoFE1Mhbnb/H+ZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Eliv/vyX832C7kE0gQu8i6ZqlUKeddYGSZ4QxxOGfAPiUROvA+RDCwxsSriKtRWYsi1C3ap3IbyC9hJCHRK7XLLd2WHNQBDwYZ+psWdbyCAY6vUtSOzvO8qT5PjWHFmMqM52T7i6TLiYLQL1T7OQnVgtni0cu1sbGLFrTfVRIe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=htYbeuAc; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="htYbeuAc" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715335106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z20fNZGFCqGAeDIBxhPRlb7sk072IN18zBHdKwtlyTE=; b=htYbeuAcAhLYNZklnby0O8snwbvSM2rqf1jrXvpgaHB0B7rL1lgx3uw05t7RXWYKXc7NX3 2/e8C/A6UqN+4iHfcgVshknDf93Z5ZB6T0zQ8Uokd4RvTf/UC8hsL0YKNZuOmNDaqT5GBg WgEAowPbAmYACMAdheVLgSjQoSU+TIU= From: kunwu.chan@linux.dev To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, kunwu.chan@hotmail.com Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH bpf-next v2 2/4] selftests/bpf/sockopt: Add a null pointer check for the run_test Date: Fri, 10 May 2024 17:58:01 +0800 Message-Id: <20240510095803.472840-3-kunwu.chan@linux.dev> In-Reply-To: <20240510095803.472840-1-kunwu.chan@linux.dev> References: <20240510095803.472840-1-kunwu.chan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan There is a 'malloc' call, which can be unsuccessful. Add the malloc failure checking to avoid possible null dereference and give more information about test fail reasons. Signed-off-by: Kunwu Chan Reviewed-by: Muhammad Usama Anjum --- tools/testing/selftests/bpf/prog_tests/sockopt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt.c b/tools/testi= ng/selftests/bpf/prog_tests/sockopt.c index 5a4491d4edfe..bde63e1f74dc 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt.c @@ -1100,6 +1100,12 @@ static int run_test(int cgroup_fd, struct sockopt_te= st *test, bool use_io_uring) } =20 optval =3D malloc(test->get_optlen); + if (!optval) { + log_err("Failed to allocate memory"); + ret =3D -1; + goto close_sock_fd; + } + memset(optval, 0, test->get_optlen); socklen_t optlen =3D test->get_optlen; socklen_t expected_get_optlen =3D test->get_optlen_ret ?: --=20 2.40.1 From nobody Sun Dec 14 19:12:29 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 DB23D16E886 for ; Fri, 10 May 2024 09:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335114; cv=none; b=VXJXChVSjOczCgh375VXnRLg2/DrcQdZm7FA5ZYkr+c9HxMkxLcG0cziF69ACafc+8bwBYPO9V0JPMUqYFdQZjnt9nzYJVEfeYzrGAYsXxD4VOjFXJx+lCI3PuC3f4hSfQhiumiFxt1md0vQmjF7dD3EjpWfh9IGAEbqEZ4/Fqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335114; c=relaxed/simple; bh=n56aSoeaesxhZLXjh7komGxYG9xTu0UlluiOU0myr0o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TXI/hLqoI2+IP8cVBH/EKcwRGqWQ+q0Ce/x5lBVh7zdf6g+/iem+p6EhY5sFm+J7vwR+FxwSewjdgSISRlEsHHErma5qvUuGRmkJMYj/9H5SzA1J0B5Q6H8AmUvS8/31+XJmAlT+917+PBQadLWBaVxZPbR6ybhRsfkZVjzQZ1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QC4d2x+U; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QC4d2x+U" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715335111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3nUhuTP23hsrziqOf8yd0GU1qZX9RbuetxzNfweNTAA=; b=QC4d2x+Uvb42OVN7atGAVYtug+FQ6KHIlk74Fp+4qQRTfZD5y9W9cKP+/1bCIje0Sg9xW6 /DOWweToYjAI014yjmDNMbdcZ2KaAQjh/PxdnETXBOWIyynRbnwMn8mdJ4mFp0GYyf2XjF e7PgIepQrPjCSDK9lkGbtseXH7HFWAk= From: kunwu.chan@linux.dev To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, kunwu.chan@hotmail.com Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH bpf-next v2 3/4] selftests/bpf: Add a null pointer check for the load_btf_spec Date: Fri, 10 May 2024 17:58:02 +0800 Message-Id: <20240510095803.472840-4-kunwu.chan@linux.dev> In-Reply-To: <20240510095803.472840-1-kunwu.chan@linux.dev> References: <20240510095803.472840-1-kunwu.chan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan There is a 'malloc' call, which can be unsuccessful. Add the malloc failure checking to avoid possible null dereference. Signed-off-by: Kunwu Chan Reviewed-by: Muhammad Usama Anjum --- tools/testing/selftests/bpf/test_verifier.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/se= lftests/bpf/test_verifier.c index df04bda1c927..9c80b2943418 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -762,6 +762,8 @@ static int load_btf_spec(__u32 *types, int types_len, ); =20 raw_btf =3D malloc(sizeof(hdr) + types_len + strings_len); + if (!raw_btf) + return -ENOMEM; =20 ptr =3D raw_btf; memcpy(ptr, &hdr, sizeof(hdr)); --=20 2.40.1 From nobody Sun Dec 14 19:12:29 2025 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 ADDEE16F0C9 for ; Fri, 10 May 2024 09:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335119; cv=none; b=qmtWi7K3sCdAh7et2byl+B3dG79y6a1czaYgIx/L6Ad3ShkGEaoPqKlPLgFoJV05B9z0iVDISJ2w9j19uwJY85koZWgiylZkEKVvBcOZUY3/OhDH6M9SgSHjCslMbJWtfc85Or1CYLRVr9MSGPgGSV+m1IUTyhfCCLWLTgISnUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715335119; c=relaxed/simple; bh=bB491r35n9N4uzXZc1q70gTMtCa6mqt+ofgDXjFs3MQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ks5BWZ/5l4ew9cdo/Pb3gj7jQwP7hVaDx+B2+J+JhNLlCctQdv7+d58scFUHNQ2BfboCPiWiSHpiAdgZLT6SSSXvmKiWuuOzR4dj82IYet09FC4ILAB9J78fSBX4vyHhnJjAcmlBG6HX6zJdW7tUpo1BykIW+pCJ6A1xipamWhw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N/iODyYK; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N/iODyYK" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715335115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/aJZjrayVmmqLyz6Ky6ChcOrC6sjpvX/LIO1l69Ryr8=; b=N/iODyYKTv6xAF8+nPjTOJa6CAmoLouxAjoxhfoA0TJudge6lBicKGj1CddBCibuFK0//A WrbwYOijJKVMh5OMczOZkwoy2FwZGhdyHnUbXIub8GhOgAOASpC0t2jP1GGbVH0T2DX41t yQpNIwfOH6cFfPCqsKNKSD+hZ4eIQ04= From: kunwu.chan@linux.dev To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, kunwu.chan@hotmail.com Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Add a null pointer check for the serial_test_tp_attach_query Date: Fri, 10 May 2024 17:58:03 +0800 Message-Id: <20240510095803.472840-5-kunwu.chan@linux.dev> In-Reply-To: <20240510095803.472840-1-kunwu.chan@linux.dev> References: <20240510095803.472840-1-kunwu.chan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan There is a 'malloc' call, which can be unsuccessful. Add the malloc failure checking to avoid possible null dereference. Signed-off-by: Kunwu Chan Suggested-by: Daniel Borkmann Reviewed-by: Muhammad Usama Anjum --- Changes in v2: - Use ASSERT* instead of CHECK - Add suggested-by tag --- tools/testing/selftests/bpf/prog_tests/tp_attach_query.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c b/too= ls/testing/selftests/bpf/prog_tests/tp_attach_query.c index 655d69f0ff0b..a5ebfc172ad8 100644 --- a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c +++ b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c @@ -39,6 +39,9 @@ void serial_test_tp_attach_query(void) attr.wakeup_events =3D 1; =20 query =3D malloc(sizeof(*query) + sizeof(__u32) * num_progs); + if (!ASSERT_OK_PTR(query, "malloc")) + return; + for (i =3D 0; i < num_progs; i++) { err =3D bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj[i], &prog_fd[i]); --=20 2.40.1