From patchwork Wed Apr 24 02:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu X-Patchwork-Id: 13640955 X-Patchwork-Delegate: bpf@iogearbox.net 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 09AB814A85; Wed, 24 Apr 2024 02:05:13 +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=1713924317; cv=none; b=qBZf3RxAUns2q5lcukJmfhkOALZ0aHIeLcGuP6x+z8vTmZDVSf2db7zAftlq6ZFLpR/3YDRgcSTxh6sm1LoUkOFYBDxoNfUuRF6cx0xHe55f+HbwL8GUZYPPUJSQnePJuLpgJ9gmxw/D23Va/6frImTUlQct1sdmdrw7nJ2hx0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713924317; c=relaxed/simple; bh=Qe4fEgUEo3+K/fSX70/eljtbReR8vF46tYGBSXlXNfM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TW60bW4f9B2obhQ7k30FcP73oFrtyUujqv8sANezR/wQoioRmltFKyj8026f3AxiJ5hWiZr9B/dZ9Uuj2sTehAHEQmlx63jqju6FG5QtVwleSw7lyEzylOGar5Lc59QB5Ryp1ZNJhr9vabEz82Evv18isfvrMZhPpWRGcnpDqGY= 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: 136d7d4401df11ef9305a59a3cc225df-20240424 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:ebc7a3ea-3fa6-4c1c-b0d1-8099f7a2579d,IP:10, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:26 X-CID-INFO: VERSION:1.1.37,REQID:ebc7a3ea-3fa6-4c1c-b0d1-8099f7a2579d,IP:10,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:26 X-CID-META: VersionHash:6f543d0,CLOUDID:d2eee06c9caf1db563cfda8d4a13907c,BulkI D:240424100509SL2PSHQB,BulkQuantity:0,Recheck:0,SF:19|43|74|66|38|24|17|10 2,TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:n il,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE: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: 136d7d4401df11ef9305a59a3cc225df-20240424 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1546720597; Wed, 24 Apr 2024 10:05:08 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 44F9FE000EB9; Wed, 24 Apr 2024 10:05:08 +0800 (CST) X-ns-mid: postfix-662868D4-48137371 Received: from kernel.. (unknown [10.42.12.206]) by mail.kylinos.cn (NSMail) with ESMTPA id EBFF1E000EB9; Wed, 24 Apr 2024 10:05:06 +0800 (CST) From: Kunwu Chan 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 1/4] selftests/bpf: Add some null pointer checks Date: Wed, 24 Apr 2024 10:04:41 +0800 Message-Id: <20240424020444.2375773-2-chentao@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424020444.2375773-1-chentao@kylinos.cn> References: <20240424020444.2375773-1-chentao@kylinos.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net 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/selftests/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 stack_trace_len) val_buf1 = malloc(stack_trace_len); val_buf2 = malloc(stack_trace_len); + if (!val_buf1 || !val_buf2) { + err = -ENOMEM; + goto out; + } + cur_key_p = NULL; next_key_p = &key; while (bpf_map_get_next_key(smap_fd, cur_key_p, next_key_p) == 0) { @@ -1197,6 +1202,8 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state) int subtest_num = state->subtest_num; state->subtest_states = malloc(subtest_num * sizeof(*subtest_state)); + if (!state->subtest_states) + return -ENOMEM; for (int i = 0; i < subtest_num; i++) { subtest_state = &state->subtest_states[i]; From patchwork Wed Apr 24 02:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu X-Patchwork-Id: 13640956 X-Patchwork-Delegate: bpf@iogearbox.net 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 50A4510949; Wed, 24 Apr 2024 02:05:16 +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=1713924319; cv=none; b=XpVk5zoEUc472TLZ5EaPpeqcDn9wuSEeMvU4mZy3WjgQT0n9NJ+4GXNqB3jcvCUwWPTU6E3BLrPXF1RONOhTfCVnRjoadIOlyzLaySNtjh8KKzyTfgQxxVXjubptevQYsZXHbvDkwD3CGlyRSAuOY13VIiSC8v94hKu3XcGoe3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713924319; c=relaxed/simple; bh=9+4lZvu5vWzgsP23GS2HmJn+dGqfZr3DPqpn22bQwec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C3ZVr7XqtC0kh3LIqEyKHeoztGjBGGIxwcawolJ9lxxNDVo4WviP5jHWeuZBBo/blMjkyXHiqeN6uWwyWYREqLPKG9nS5DYicPkY1TA7+bK2PXCpo5apd0fOsEIgrY4CWne1LKFwQnYYygDTioFDfDMY+ejI/4eK5mzege/r0JU= 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: 14626d5e01df11ef9305a59a3cc225df-20240424 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:00bb5884-1e70-46a1-ac51-60fb1aa7f575,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:1 X-CID-INFO: VERSION:1.1.37,REQID:00bb5884-1e70-46a1-ac51-60fb1aa7f575,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:6f543d0,CLOUDID:5d12c84477d2f1f51e1f0934456e5441,BulkI D:240424100512R7PQ4BJ4,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|43|74|10 2,TC:nil,Content:0,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 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-UUID: 14626d5e01df11ef9305a59a3cc225df-20240424 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1064384468; Wed, 24 Apr 2024 10:05:10 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id D700AE000EB9; Wed, 24 Apr 2024 10:05:09 +0800 (CST) X-ns-mid: postfix-662868D5-666104372 Received: from kernel.. (unknown [10.42.12.206]) by mail.kylinos.cn (NSMail) with ESMTPA id 4F068E000EBB; Wed, 24 Apr 2024 10:05:08 +0800 (CST) From: Kunwu Chan 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 2/4] selftests/bpf/sockopt: Add a null pointer check for the run_test Date: Wed, 24 Apr 2024 10:04:42 +0800 Message-Id: <20240424020444.2375773-3-chentao@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424020444.2375773-1-chentao@kylinos.cn> References: <20240424020444.2375773-1-chentao@kylinos.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net 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 --- 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/testing/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_test *test, bool use_io_uring) } optval = malloc(test->get_optlen); + if (!optval) { + log_err("Failed to allocate memory"); + ret = -1; + goto close_sock_fd; + } + memset(optval, 0, test->get_optlen); socklen_t optlen = test->get_optlen; socklen_t expected_get_optlen = test->get_optlen_ret ?: From patchwork Wed Apr 24 02:04:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu X-Patchwork-Id: 13640957 X-Patchwork-Delegate: bpf@iogearbox.net 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 BFE111A29A; Wed, 24 Apr 2024 02:05:17 +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=1713924320; cv=none; b=RkgaVpEsES4o24+0xorzCALROqNRZHrg1VQHm2OlnARjmAUkHGIVAdW+SiuoDkBejnZOkOkkvpKVj/yOObr9CKjaYPtMJ4qkkGJZo3j9iWTAkPvVE+8+24yjw/cxWoWjhnQikUKWtdcY4wOCOOoqHPIR5o3OgTzZ5mFLUt6fzww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713924320; c=relaxed/simple; bh=ACgsItn8OBoe+YbzAGxCaUt5pzTAl9TfLFs6OvA0SL0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VOV0CTSpDf4saBKlWJQFw2qQDcFdlLN/tA1R9dfaZZLUAscFqTYrHK3utHpt2nmem8ZLKPi1NalUvBH84spwzGlFLH6r51fqE1xUKmovOj00zIz5jL0+3aQ01ycPVNDQh/GeBYEHx3lG7QJ/IJthtr3Xzw0EjnVqwLR1poNPgDI= 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: 15347db201df11ef9305a59a3cc225df-20240424 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:85785f5e-63af-4590-bb1f-d09fd9974604,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:1 X-CID-INFO: VERSION:1.1.37,REQID:85785f5e-63af-4590-bb1f-d09fd9974604,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:6f543d0,CLOUDID:4620fbdcf84b357a5ff4bb413a22bc27,BulkI D:240424100512622X49TE,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|43|74|10 2,TC:nil,Content:0,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 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: 15347db201df11ef9305a59a3cc225df-20240424 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1552464066; Wed, 24 Apr 2024 10:05:11 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 2FF86E000EB9; Wed, 24 Apr 2024 10:05:11 +0800 (CST) X-ns-mid: postfix-662868D6-985344373 Received: from kernel.. (unknown [10.42.12.206]) by mail.kylinos.cn (NSMail) with ESMTPA id E134CE000EBB; Wed, 24 Apr 2024 10:05:09 +0800 (CST) From: Kunwu Chan 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 3/4] selftests/bpf: Add a null pointer check for the load_btf_spec Date: Wed, 24 Apr 2024 10:04:43 +0800 Message-Id: <20240424020444.2375773-4-chentao@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424020444.2375773-1-chentao@kylinos.cn> References: <20240424020444.2375773-1-chentao@kylinos.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net There is a 'malloc' call, which can be unsuccessful. Add the malloc failure checking to avoid possible null dereference. Signed-off-by: Kunwu Chan --- 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/selftests/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, ); raw_btf = malloc(sizeof(hdr) + types_len + strings_len); + if (!raw_btf) + return -ENOMEM; ptr = raw_btf; memcpy(ptr, &hdr, sizeof(hdr)); From patchwork Wed Apr 24 02:04:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu X-Patchwork-Id: 13640958 X-Patchwork-Delegate: bpf@iogearbox.net 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 D88FE1D54B; Wed, 24 Apr 2024 02:05:19 +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=1713924323; cv=none; b=USKLLOHdN633SlgTpDDkF3jqrsm6LokVtRK6NWruKoW2FB3bSEisLqAbHecHOMYrtZLb49Vdbu8t3Ug1cRlLCgTBEovb63KI3zlnJbJ3cnx7o91BhQfaiEpCP8DdgQ8+B+z2vdbMICJdusJxa0DSxK6lO7TQ/x0oH5NzMytFTZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713924323; c=relaxed/simple; bh=bwn4NKPDjBjaNuo3yEiLyY1cpnHyL8Uv30pKNbsM170=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GBfluh9oMVOfsOd09Z76ead5oFPOhjsx42gQD8tqT+Ashtj4VCs6geH8VZzcDnnPhJgzLbfUz1PJ/arj+fbsZoubcu0s3ZmtJc7z6TOHVyPEcL2uLsmw1JBlEz8/s8tY0iQ8kjVoE9CXQBEP/033jDJUJTSPnpXHh6MVWi1QU3Q= 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: 161efcb601df11ef9305a59a3cc225df-20240424 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:669ee238-3864-44f8-91ba-1556b251d4d0,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:1 X-CID-INFO: VERSION:1.1.37,REQID:669ee238-3864-44f8-91ba-1556b251d4d0,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:6f543d0,CLOUDID:ae00a2f80363ef3acd4c7fc3192d941f,BulkI D:240424100515AGH5VMPW,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|43|74|10 2,TC:nil,Content:0,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 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR X-UUID: 161efcb601df11ef9305a59a3cc225df-20240424 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1332634441; Wed, 24 Apr 2024 10:05:13 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 8A546E000EB9; Wed, 24 Apr 2024 10:05:12 +0800 (CST) X-ns-mid: postfix-662868D8-327764374 Received: from kernel.. (unknown [10.42.12.206]) by mail.kylinos.cn (NSMail) with ESMTPA id 3B3DCE000EBB; Wed, 24 Apr 2024 10:05:11 +0800 (CST) From: Kunwu Chan 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 4/4] selftests/bpf: Add a null pointer check for the serial_test_tp_attach_query Date: Wed, 24 Apr 2024 10:04:44 +0800 Message-Id: <20240424020444.2375773-5-chentao@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424020444.2375773-1-chentao@kylinos.cn> References: <20240424020444.2375773-1-chentao@kylinos.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net There is a 'malloc' call, which can be unsuccessful. Add the malloc failure checking to avoid possible null dereference. Signed-off-by: Kunwu Chan --- 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/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c index 655d69f0ff0b..302b25408a53 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 = 1; query = malloc(sizeof(*query) + sizeof(__u32) * num_progs); + if (CHECK(!query, "malloc()", "error:%s\n", strerror(errno))) + return; + for (i = 0; i < num_progs; i++) { err = bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj[i], &prog_fd[i]);