From: Shuah Khan <skhan@linuxfoundation.org>
To: Malaya Kumar Rout <malayarout91@gmail.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Cc: mrout@redhat.com, me@brighamcampbell.com,
Thomas Renninger <trenn@suse.com>, Shuah Khan <shuah@kernel.org>,
"John B. Wyatt IV" <jwyatt@redhat.com>,
John Kacur <jkacur@redhat.com>,
Brahadambal Srinivasan <latha@linux.vnet.ibm.com>,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] cpupower: Fix NULL pointer dereference on allocation failure
Date: Thu, 16 Jul 2026 16:16:04 -0600 [thread overview]
Message-ID: <71c8ae0d-cc20-4b99-92c6-69641b2a0f85@linuxfoundation.org> (raw)
In-Reply-To: <20260704084303.86113-1-malayarout91@gmail.com>
On 7/4/26 02:43, Malaya Kumar Rout wrote:
> The bitmask_alloc() function can return NULL if memory allocation fails,
> but the code in main() does not check the return values before using the
> allocated bitmasks. This can lead to a NULL pointer dereference when
> bitmask_setall() or bitmask_parselist() is called with NULL pointers.
>
> Add proper NULL checks after bitmask allocations and exit gracefully with
> an error message if allocation fails.
>
> Fixes: 748f0d70087c ("cpupower: Provide online and offline CPU information")
> Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
> ---
> tools/power/cpupower/utils/cpupower.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
> index 9ec973165af1..8f7b18b8bb43 100644
> --- a/tools/power/cpupower/utils/cpupower.c
> +++ b/tools/power/cpupower/utils/cpupower.c
> @@ -184,6 +184,17 @@ int main(int argc, const char *argv[])
> online_cpus = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF));
> offline_cpus = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF));
>
> + if (!cpus_chosen || !online_cpus || !offline_cpus) {
> + fprintf(stderr, _("Failed to allocate bitmasks\n"));
> + if (cpus_chosen)
> + bitmask_free(cpus_chosen);
> + if (online_cpus)
> + bitmask_free(online_cpus);
> + if (offline_cpus)
> + bitmask_free(offline_cpus);
> + return EXIT_FAILURE;
> + }
> +
> argc--;
> argv += 1;
>
Usually these small allocations don't fail to warrant checks.
thanks,
-- Shuah
prev parent reply other threads:[~2026-07-16 22:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 8:43 [PATCH] cpupower: Fix NULL pointer dereference on allocation failure Malaya Kumar Rout
2026-07-16 22:16 ` Shuah Khan [this message]
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=71c8ae0d-cc20-4b99-92c6-69641b2a0f85@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jkacur@redhat.com \
--cc=jwyatt@redhat.com \
--cc=latha@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=malayarout91@gmail.com \
--cc=me@brighamcampbell.com \
--cc=mrout@redhat.com \
--cc=shuah@kernel.org \
--cc=trenn@suse.com \
/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