* [PATCH][next] kobject: fix dereference before null check on kobj
@ 2019-05-01 12:43 Colin King
2019-05-01 13:08 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2019-05-01 12:43 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
The kobj pointer is being null-checked so potentially it could be null,
however, the ktype declaration before the null check is dereferencing kobj
hence we have a potential null pointer deference. Fix this by moving the
assignment of ktype after kobj has been null checked.
Addresses-Coverity: ("Dereference before null check")
Fixes: aa30f47cf666 ("kobject: Add support for default attribute groups to kobj_type")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
lib/kobject.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/kobject.c b/lib/kobject.c
index a30ee0467942..095bcb55c2ba 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -603,12 +603,13 @@ EXPORT_SYMBOL_GPL(kobject_move);
void kobject_del(struct kobject *kobj)
{
struct kernfs_node *sd;
- const struct kobj_type *ktype = get_ktype(kobj);
+ const struct kobj_type *ktype;
if (!kobj)
return;
sd = kobj->sd;
+ ktype = get_ktype(kobj);
if (ktype)
sysfs_remove_groups(kobj, ktype->default_groups);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] kobject: fix dereference before null check on kobj
2019-05-01 12:43 [PATCH][next] kobject: fix dereference before null check on kobj Colin King
@ 2019-05-01 13:08 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2019-05-01 13:08 UTC (permalink / raw)
To: Colin King; +Cc: Rafael J . Wysocki, kernel-janitors, linux-kernel
On Wed, May 01, 2019 at 01:43:17PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The kobj pointer is being null-checked so potentially it could be null,
> however, the ktype declaration before the null check is dereferencing kobj
> hence we have a potential null pointer deference. Fix this by moving the
> assignment of ktype after kobj has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: aa30f47cf666 ("kobject: Add support for default attribute groups to kobj_type")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> lib/kobject.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Nice catch, thanks, will go queue this up now.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-01 13:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 12:43 [PATCH][next] kobject: fix dereference before null check on kobj Colin King
2019-05-01 13:08 ` Greg Kroah-Hartman
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 NNTP newsgroup(s).