From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: 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: Muhammad Usama Anjum <usama.anjum@collabora.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>
Subject: Re: [PATCH bpf-next v2 2/4] selftests/bpf/sockopt: Add a null pointer check for the run_test
Date: Fri, 10 May 2024 16:22:27 +0500 [thread overview]
Message-ID: <e3d20115-df52-4d1f-98d6-928277f9ca36@collabora.com> (raw)
In-Reply-To: <20240510095803.472840-3-kunwu.chan@linux.dev>
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.
> Add the malloc failure checking to avoid possible null
> dereference and give more information
> about test fail reasons.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
LGTM
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> 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 ?:
--
BR,
Muhammad Usama Anjum
next prev parent reply other threads:[~2024-05-10 11:22 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
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 [this message]
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=e3d20115-df52-4d1f-98d6-928277f9ca36@collabora.com \
--to=usama.anjum@collabora.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chentao@kylinos.cn \
--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=kunwu.chan@linux.dev \
--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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).