linux/Documentation/admin-guide/LSM
Konstantin Andreev f0a9ef99fb smack: fix bug: setting task label silently ignores input garbage
[ Upstream commit 674e2b2479 ]

This command:
    # echo foo/bar >/proc/$$/attr/smack/current

gives the task a label 'foo' w/o indication
that label does not match input.
Setting the label with lsm_set_self_attr() syscall
behaves identically.

This occures because:

1) smk_parse_smack() is used to convert input to a label
2) smk_parse_smack() takes only that part from the
   beginning of the input that looks like a label.
3) `/' is prohibited in labels, so only "foo" is taken.

(2) is by design, because smk_parse_smack() is used
for parsing strings which are more than just a label.

Silent failure is not a good thing, and there are two
indicators that this was not done intentionally:

    (size >= SMK_LONGLABEL) ~> invalid

clause at the beginning of the do_setattr() and the
"Returns the length of the smack label" claim
in the do_setattr() description.

So I fixed this by adding one tiny check:
the taken label length == input length.

Since input length is now strictly controlled,
I changed the two ways of setting label

   smack_setselfattr(): lsm_set_self_attr() syscall
   smack_setprocattr(): > /proc/.../current

to accommodate the divergence in
what they understand by "input length":

  smack_setselfattr counts mandatory \0 into input length,
  smack_setprocattr does not.

  smack_setprocattr allows various trailers after label

Related changes:

* fixed description for smk_parse_smack

* allow unprivileged tasks validate label syntax.

* extract smk_parse_label_len() from smk_parse_smack()
  so parsing may be done w/o string allocation.

* extract smk_import_valid_label() from smk_import_entry()
  to avoid repeated parsing.

* smk_parse_smack(): scan null-terminated strings
  for no more than SMK_LONGLABEL(256) characters

* smack_setselfattr(): require struct lsm_ctx . flags == 0
  to reserve them for future.

Fixes: e114e47377 ("Smack: Simplified Mandatory Access Control Kernel")
Signed-off-by: Konstantin Andreev <andreev@swemel.ru>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-12-18 13:54:40 +01:00
..
apparmor.rst apparmor: update git and wiki locations in AppArmor docs 2018-06-07 01:50:47 -07:00
index.rst documentation: add IPE documentation 2024-08-20 14:03:47 -04:00
ipe.rst ipe: allow secondary and platform keyrings to install/update policies 2024-10-17 11:46:10 -07:00
LoadPin.rst security/loadpin: Update the changing interface in the source code. 2021-03-15 13:32:32 -06:00
SafeSetID.rst docs: SafeSetID: fix a warning 2020-10-28 11:42:02 -06:00
SELinux.rst Documentation: Update SELinux reference policy URL 2018-11-19 12:40:48 -05:00
Smack.rst smack: fix bug: setting task label silently ignores input garbage 2025-12-18 13:54:40 +01:00
tomoyo.rst tomoyo: update project links 2024-06-03 22:43:11 +09:00
Yama.rst doc: yama: Swap HTTP for HTTPS and replace dead link 2020-07-13 09:40:42 -06:00