SMACK: Fix handling value==NULL in post setxattr
authorJosé Bollo <jose.bollo@open.eurogiciel.org>
Thu, 3 Apr 2014 07:51:07 +0000 (09:51 +0200)
committerStephane Desneux <stephane.desneux@open.eurogiciel.org>
Tue, 25 Nov 2014 09:08:28 +0000 (10:08 +0100)
commitf7723d32c993ea1e00bc11d9ef1c4a9ba2050f31
tree786327be3c3a693c6619910fe8ba896b682e8041
parentf029d2b6e4516c4ea5ecc9a740f4cafadb081330
SMACK: Fix handling value==NULL in post setxattr

The function `smack_inode_post_setxattr` is called each
time that a setxattr is done, for any value of name.
The kernel allow to put value==NULL when size==0
to set an empty attribute value. The systematic
call to smk_import_entry was causing the dereference
of a NULL pointer hence a KERNEL PANIC!

The problem can be produced easily by issuing the
command `setfattr -n user.data file` under bash prompt
when SMACK is active.

Moving the call to smk_import_entry as proposed by this
patch is correcting the behaviour because the function
smack_inode_post_setxattr is called for the SMACK's
attributes only if the function smack_inode_setxattr validated
the value and its size (what will not be the case when size==0).

It also has a benefical effect to not fill the smack hash
with garbage values coming from any extended attribute
write.

Change-Id: Iaf0039c2be9bccb6cee11c24a3b44d209101fe47
Signed-off-by: José Bollo <jose.bollo@open.eurogiciel.org>
Signed-off-by: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
security/smack/smack_lsm.c