From: Andrew Morton <akpm@linux-foundation.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: pmladek@suse.com, valentin.schneider@arm.com,
peterz@infradead.org, keescook@chromium.org,
robdclark@chromium.org, samitolvanen@google.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kthread: potential dereference of null pointer
Date: Fri, 10 Dec 2021 13:16:55 -0800 [thread overview]
Message-ID: <20211210131655.2eeb8f866382c324b605a6ce@linux-foundation.org> (raw)
In-Reply-To: <20211209064314.2074885-1-jiasheng@iscas.ac.cn>
On Thu, 9 Dec 2021 14:43:14 +0800 Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
> The return value of kzalloc() needs to be checked.
> To avoid use of null pointer in case of the failure of alloc.
>
> ...
>
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -101,6 +101,8 @@ void set_kthread_struct(struct task_struct *p)
> return;
>
> kthread = kzalloc(sizeof(*kthread), GFP_KERNEL);
> + if (!kthread)
> + return;
> /*
> * We abuse ->set_child_tid to avoid the new member and because it
> * can't be wrongly copied by copy_process(). We also rely on fact
No, we shouldn't simply leave ->set_child_tid uninitialized if kmalloc
failed.
set_ktread_struct() appears to be designed so that callers must check
that to_kthread() returns non-zero after having called
set_kthread_struct().
Which is a quite weird interface, but I'm not seeing any bugs here. If
kthread() sees to_kthread()==NULL then this kthread won't be created
and all the other unchecked calls to to_kthread() will never execute,
because this kthread doesn't exist.
The exception is in init_idle(), but that's __init code, executed at
boot time when we assume that allocations will always succeed.
prev parent reply other threads:[~2021-12-10 21:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-09 6:43 Jiasheng Jiang
2021-12-09 9:24 ` Petr Mladek
2021-12-10 21:16 ` Andrew Morton [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=20211210131655.2eeb8f866382c324b605a6ce@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jiasheng@iscas.ac.cn \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=robdclark@chromium.org \
--cc=samitolvanen@google.com \
--cc=valentin.schneider@arm.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
all inboxes | Powered by JetHome®