BACKPORT: Smack: handle zero-length security labels without panic
authorKonstantin Khlebnikov <k.khlebnikov@samsung.com>
Thu, 7 Aug 2014 16:52:43 +0000 (20:52 +0400)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 30 Jun 2016 12:57:38 +0000 (14:57 +0200)
commitd6d099cc3bf10260ce42484f1b780d77a6bd365e
tree44d73967f9403ba05f2c7519cf05d551033d4681
parentc6ea93cf7a7143e1ca9b102441a25b2db23de641
BACKPORT: Smack: handle zero-length security labels without panic

Zero-length security labels are invalid but kernel should handle them.

This patch fixes kernel panic after setting zero-length security labels:
# attr -S -s "SMACK64" -V "" file

And after writing zero-length string into smackfs files syslog and onlycp:
# python -c 'import os; os.write(1, "")' > /smack/syslog

The problem is caused by brain-damaged logic in function smk_parse_smack()
which takes pointer to buffer and its length but if length below or equal zero
it thinks that the buffer is zero-terminated. Unfortunately callers of this
function are widely used and proper fix requires serious refactoring.

Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
(cherry-picked from upstream b862e561bad6372872f5bf98d95f4131d265b110)
security/smack/smack_lsm.c
security/smack/smackfs.c