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)
committerDamian Hobson-Garcia <dhobsong@igel.co.jp>
Thu, 11 Dec 2014 07:53:31 +0000 (16:53 +0900)
commitefe56b18f2ce21a508a27d03b3400d553bc31e05
treecb447f5efc54ff1b400bc4579044b9cf132c7f18
parent5bea3f230102ec819ae347aae57b360bc580b241
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:

And after writing zero-length string into smackfs files syslog and onlycp:

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.

Change-Id: I931735ccfaea4d8d2f0a98eacf8467f0a8359bc6
Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
(cherry picked from commit ae5c52ea68b54756c3211e983ada23169b300474)

Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
security/smack/smack_lsm.c
security/smack/smackfs.c