From: Shuah Khan <skhan@linuxfoundation.org>
To: Colin Ian King <colin.i.king@gmail.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>,
Shuah Khan <shuah@kernel.org>, Babu Moger <babu.moger@amd.com>,
Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
linux-kselftest@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests/resctrl: Fix null pointer dereference on open failed
Date: Mon, 25 Apr 2022 09:51:16 -0600 [thread overview]
Message-ID: <04a35a47-d83a-67a1-5ed4-ba314c6e1ecf@linuxfoundation.org> (raw)
In-Reply-To: <20220424211536.1373878-1-colin.i.king@gmail.com>
On 4/24/22 3:15 PM, Colin Ian King wrote:
> Currently if opening /dev/null fails to open then file pointer fp
> is null and further access to fp via fprintf will cause a null
> pointer dereference. Fix this by returning a negative error value
> when a null fp is detected.
>
How did you find this problem and how can it be reproduced? Is there
a case where test fails to open "/dev/null"?
> Fixes: a2561b12fe39 ("selftests/resctrl: Add built in benchmark")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
> tools/testing/selftests/resctrl/fill_buf.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c
> index 51e5cf22632f..56ccbeae0638 100644
> --- a/tools/testing/selftests/resctrl/fill_buf.c
> +++ b/tools/testing/selftests/resctrl/fill_buf.c
> @@ -121,8 +121,10 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr,
>
> /* Consume read result so that reading memory is not optimized out. */
> fp = fopen("/dev/null", "w");
> - if (!fp)
> + if (!fp) {
> perror("Unable to write to /dev/null");
> + return -1;
> + }
> fprintf(fp, "Sum: %d ", ret);
> fclose(fp);
>
>
thanks,
-- Shuah
next prev parent reply other threads:[~2022-04-25 15:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-24 21:15 [PATCH] selftests/resctrl: Fix null pointer dereference on open failed Colin Ian King
2022-04-25 15:51 ` Shuah Khan [this message]
2022-04-25 16:06 ` Colin King (gmail)
2022-04-25 16:21 ` Shuah Khan
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=04a35a47-d83a-67a1-5ed4-ba314c6e1ecf@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=babu.moger@amd.com \
--cc=colin.i.king@gmail.com \
--cc=fenghua.yu@intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=sai.praneeth.prakhya@intel.com \
--cc=shuah@kernel.org \
/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