* [cgroup:for-next 5/6] fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
@ 2012-09-12 2:28 Fengguang Wu
2012-09-12 7:55 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Fengguang Wu @ 2012-09-12 2:28 UTC (permalink / raw)
To: Aristeu Rozanski
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Tejun Heo,
cgroups-u79uwXL29TY76Z2rM5mHXA, Dan Carpenter
Hi Aristeu,
FYI, there are new smatch warnings show up in
tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
head: 9814e970d7947dcc5ab7b37a53514c0098bfacc9
commit: 38f38657444d15e1a8574eae80ed3de9f501737a xattr: extract simple_xattr code from tmpfs
fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
vim +882 fs/xattr.c
872 } else {
873 list_del(&xattr->list);
874 }
875 goto out;
876 }
877 }
878 if (flags & XATTR_REPLACE) {
879 xattr = new_xattr;
880 err = -ENODATA;
881 } else {
> 882 list_add(&new_xattr->list, &xattrs->head);
883 xattr = NULL;
884 }
885 out:
886 spin_unlock(&xattrs->lock);
887 if (xattr) {
888 kfree(xattr->name);
889 kfree(xattr);
890 }
891 return err;
892
---
0-DAY kernel build testing backend Open Source Technology Centre
Fengguang Wu <wfg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> Intel Corporation
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cgroup:for-next 5/6] fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
2012-09-12 2:28 [cgroup:for-next 5/6] fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr' Fengguang Wu
@ 2012-09-12 7:55 ` Dan Carpenter
2012-09-12 13:40 ` Aristeu Rozanski
2012-09-12 14:31 ` [PATCH] xattr: mark variable as uninitialized to make both gcc and smatch happy Aristeu Rozanski
0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2012-09-12 7:55 UTC (permalink / raw)
To: Fengguang Wu
Cc: Aristeu Rozanski, kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
Tejun Heo, cgroups-u79uwXL29TY76Z2rM5mHXA
On Wed, Sep 12, 2012 at 10:28:13AM +0800, Fengguang Wu wrote:
> Hi Aristeu,
>
> FYI, there are new smatch warnings show up in
>
> tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
> head: 9814e970d7947dcc5ab7b37a53514c0098bfacc9
> commit: 38f38657444d15e1a8574eae80ed3de9f501737a xattr: extract simple_xattr code from tmpfs
>
>
> fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
>
I don't know if this specific code is buggy or not. It would depend
on how the function is called.
But potentially I should disable this Smatch rule. It tends to have
a lot of false positives. The thing is that GCC complains if you
don't initialize "new_xattr", but if you initialize it to NULL then
Smatch complains.
One solution might be to use the unitialized_var() macro.
- struct simple_xattr *new_xattr = NULL;
+ struct simple_xattr *uninitialized_var(new_xattr);
That would make both GCC and Smatch happy.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cgroup:for-next 5/6] fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
2012-09-12 7:55 ` Dan Carpenter
@ 2012-09-12 13:40 ` Aristeu Rozanski
2012-09-12 14:31 ` [PATCH] xattr: mark variable as uninitialized to make both gcc and smatch happy Aristeu Rozanski
1 sibling, 0 replies; 5+ messages in thread
From: Aristeu Rozanski @ 2012-09-12 13:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Fengguang Wu, kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Tejun Heo,
cgroups-u79uwXL29TY76Z2rM5mHXA
On Wed, Sep 12, 2012 at 10:55:17AM +0300, Dan Carpenter wrote:
> On Wed, Sep 12, 2012 at 10:28:13AM +0800, Fengguang Wu wrote:
> > Hi Aristeu,
> >
> > FYI, there are new smatch warnings show up in
> >
> > tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
> > head: 9814e970d7947dcc5ab7b37a53514c0098bfacc9
> > commit: 38f38657444d15e1a8574eae80ed3de9f501737a xattr: extract simple_xattr code from tmpfs
> >
> >
> > fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr'.
> >
>
> I don't know if this specific code is buggy or not. It would depend
> on how the function is called.
this should be safe. the only way to have value == NULL (thus keeping
new_xattr from being initialized) is if you call __simple_xattr_set()
directly with the intention of removing an existing entry.
> But potentially I should disable this Smatch rule. It tends to have
> a lot of false positives. The thing is that GCC complains if you
> don't initialize "new_xattr", but if you initialize it to NULL then
> Smatch complains.
>
> One solution might be to use the unitialized_var() macro.
>
> - struct simple_xattr *new_xattr = NULL;
> + struct simple_xattr *uninitialized_var(new_xattr);
>
> That would make both GCC and Smatch happy.
Sounds good to me. Will get a patch ready. Thanks Dan.
--
Aristeu
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] xattr: mark variable as uninitialized to make both gcc and smatch happy
2012-09-12 7:55 ` Dan Carpenter
2012-09-12 13:40 ` Aristeu Rozanski
@ 2012-09-12 14:31 ` Aristeu Rozanski
[not found] ` <20120912143112.GE19694-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 5+ messages in thread
From: Aristeu Rozanski @ 2012-09-12 14:31 UTC (permalink / raw)
To: cgroups-u79uwXL29TY76Z2rM5mHXA
Cc: Fengguang Wu, kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Tejun Heo,
Dan Carpenter
new_xattr in __simple_xattr_set() is only initialized with a valid
pointer if value is not NULL, which only happens if this function is
called directly with the intention to remove an existing extended
attribute. Even being safe to be this way, smatch warns about possible
NULL dereference. Dan Carpenter suggested using uninitialized_var()
which will make both gcc and smatch happy.
Cc: Fengguang Wu <fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Aristeu Rozanski <aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
fs/xattr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/fs/xattr.c 2012-09-12 09:57:35.000000000 -0400
+++ b/fs/xattr.c 2012-09-12 09:58:25.619387047 -0400
@@ -845,7 +845,7 @@ static int __simple_xattr_set(struct sim
const void *value, size_t size, int flags)
{
struct simple_xattr *xattr;
- struct simple_xattr *new_xattr = NULL;
+ struct simple_xattr *uninitialized_var(new_xattr);
int err = 0;
/* value == NULL means remove */
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-12 18:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-12 2:28 [cgroup:for-next 5/6] fs/xattr.c:882 __simple_xattr_set() error: potential NULL dereference 'new_xattr' Fengguang Wu
2012-09-12 7:55 ` Dan Carpenter
2012-09-12 13:40 ` Aristeu Rozanski
2012-09-12 14:31 ` [PATCH] xattr: mark variable as uninitialized to make both gcc and smatch happy Aristeu Rozanski
[not found] ` <20120912143112.GE19694-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-09-12 18:42 ` Tejun Heo
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).