All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@linux.dev>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>,
	kunwu.chan@linux.dev, 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
Subject: Re: [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks
Date: Mon, 13 May 2024 15:00:30 +0800	[thread overview]
Message-ID: <b666dbe4-e406-44fc-8bb7-122e6c007948@linux.dev> (raw)
In-Reply-To: <a6172c6e-3b5b-43e5-8678-9dc4e428cf94@collabora.com>

On 2024/5/10 19:20, Muhammad Usama Anjum wrote:
> On 5/10/24 2:58 PM, kunwu.chan@linux.dev wrote:
>> From: Kunwu Chan <chentao@kylinos.cn>
>>
>> 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 <chentao@kylinos.cn>
>> ---
>>   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;
> Return from here instead of going to out where free(val_buf*) is being called.
I think it's no harm.  And Unify the processing at the end to achieve 
uniform format.
>> +		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];

-- 
Thanks,
   Kunwu.Chan


  reply	other threads:[~2024-05-13  7:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10  9:57 [PATCH bpf-next v2 0/4] Add some 'malloc' failure checks kunwu.chan
2024-05-10  9:58 ` [PATCH bpf-next v2 1/4] selftests/bpf: Add some null pointer checks kunwu.chan
2024-05-10 11:20   ` Muhammad Usama Anjum
2024-05-13  7:00     ` Kunwu Chan [this message]
2024-05-13  7:52   ` Markus Elfring
2024-05-10  9:58 ` [PATCH bpf-next v2 2/4] selftests/bpf/sockopt: Add a null pointer check for the run_test kunwu.chan
2024-05-10 11:22   ` Muhammad Usama Anjum
2024-05-10  9:58 ` [PATCH bpf-next v2 3/4] selftests/bpf: Add a null pointer check for the load_btf_spec kunwu.chan
2024-05-10 11:23   ` Muhammad Usama Anjum
2024-05-10  9:58 ` [PATCH bpf-next v2 4/4] selftests/bpf: Add a null pointer check for the serial_test_tp_attach_query kunwu.chan
2024-05-10 11:24   ` Muhammad Usama Anjum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b666dbe4-e406-44fc-8bb7-122e6c007948@linux.dev \
    --to=kunwu.chan@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kunwu.chan@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=usama.anjum@collabora.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.