Skip to content

Commit 09b9995

Browse files
Ondrej Mosnacekgregkh
authored andcommitted
selinux: fix empty write to keycreate file
[ Upstream commit 464c258 ] When sid == 0 (we are resetting keycreate_sid to the default value), we should skip the KEY__CREATE check. Before this patch, doing a zero-sized write to /proc/self/keycreate would check if the current task can create unlabeled keys (which would usually fail with -EACCESS and generate an AVC). Now it skips the check and correctly sets the task's keycreate_sid to 0. Bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1719067 Tested using the reproducer from the report above. Fixes: 4eb582c ("[PATCH] keys: add a way to store the appropriate context for newly-created keys") Reported-by: Kir Kolyshkin <kir@sacred.ru> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4cb2edf commit 09b9995

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,11 +6351,12 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
63516351
} else if (!strcmp(name, "fscreate")) {
63526352
tsec->create_sid = sid;
63536353
} else if (!strcmp(name, "keycreate")) {
6354-
error = avc_has_perm(&selinux_state,
6355-
mysid, sid, SECCLASS_KEY, KEY__CREATE,
6356-
NULL);
6357-
if (error)
6358-
goto abort_change;
6354+
if (sid) {
6355+
error = avc_has_perm(&selinux_state, mysid, sid,
6356+
SECCLASS_KEY, KEY__CREATE, NULL);
6357+
if (error)
6358+
goto abort_change;
6359+
}
63596360
tsec->keycreate_sid = sid;
63606361
} else if (!strcmp(name, "sockcreate")) {
63616362
tsec->sockcreate_sid = sid;

0 commit comments

Comments
 (0)