Skip to content

Commit 4a87b19

Browse files
committed
Merge tag 'LSM-add-setgid-hook-5.8-author-fix' of git://github.com/micah-morton/linux
Pull SafeSetID update from Micah Morton: "Add additional LSM hooks for SafeSetID SafeSetID is capable of making allow/deny decisions for set*uid calls on a system, and we want to add similar functionality for set*gid calls. The work to do that is not yet complete, so probably won't make it in for v5.8, but we are looking to get this simple patch in for v5.8 since we have it ready. We are planning on the rest of the work for extending the SafeSetID LSM being merged during the v5.9 merge window" * tag 'LSM-add-setgid-hook-5.8-author-fix' of git://github.com/micah-morton/linux: security: Add LSM hooks to set*gid syscalls
2 parents 9d645db + 39030e1 commit 4a87b19

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ LSM_HOOK(int, 0, kernel_post_read_file, struct file *file, char *buf,
191191
loff_t size, enum kernel_read_file_id id)
192192
LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old,
193193
int flags)
194+
LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old,
195+
int flags)
194196
LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid)
195197
LSM_HOOK(int, 0, task_getpgid, struct task_struct *p)
196198
LSM_HOOK(int, 0, task_getsid, struct task_struct *p)

include/linux/lsm_hooks.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,15 @@
659659
* @old is the set of credentials that are being replaces
660660
* @flags contains one of the LSM_SETID_* values.
661661
* Return 0 on success.
662+
* @task_fix_setgid:
663+
* Update the module's state after setting one or more of the group
664+
* identity attributes of the current process. The @flags parameter
665+
* indicates which of the set*gid system calls invoked this hook.
666+
* @new is the set of credentials that will be installed. Modifications
667+
* should be made to this rather than to @current->cred.
668+
* @old is the set of credentials that are being replaced.
669+
* @flags contains one of the LSM_SETID_* values.
670+
* Return 0 on success.
662671
* @task_setpgid:
663672
* Check permission before setting the process group identifier of the
664673
* process @p to @pgid.

include/linux/security.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
392392
enum kernel_read_file_id id);
393393
int security_task_fix_setuid(struct cred *new, const struct cred *old,
394394
int flags);
395+
int security_task_fix_setgid(struct cred *new, const struct cred *old,
396+
int flags);
395397
int security_task_setpgid(struct task_struct *p, pid_t pgid);
396398
int security_task_getpgid(struct task_struct *p);
397399
int security_task_getsid(struct task_struct *p);
@@ -1036,6 +1038,13 @@ static inline int security_task_fix_setuid(struct cred *new,
10361038
return cap_task_fix_setuid(new, old, flags);
10371039
}
10381040

1041+
static inline int security_task_fix_setgid(struct cred *new,
1042+
const struct cred *old,
1043+
int flags)
1044+
{
1045+
return 0;
1046+
}
1047+
10391048
static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
10401049
{
10411050
return 0;

kernel/sys.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ long __sys_setregid(gid_t rgid, gid_t egid)
393393
new->sgid = new->egid;
394394
new->fsgid = new->egid;
395395

396+
retval = security_task_fix_setgid(new, old, LSM_SETID_RE);
397+
if (retval < 0)
398+
goto error;
399+
396400
return commit_creds(new);
397401

398402
error:
@@ -435,6 +439,10 @@ long __sys_setgid(gid_t gid)
435439
else
436440
goto error;
437441

442+
retval = security_task_fix_setgid(new, old, LSM_SETID_ID);
443+
if (retval < 0)
444+
goto error;
445+
438446
return commit_creds(new);
439447

440448
error:
@@ -756,6 +764,10 @@ long __sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
756764
new->sgid = ksgid;
757765
new->fsgid = new->egid;
758766

767+
retval = security_task_fix_setgid(new, old, LSM_SETID_RES);
768+
if (retval < 0)
769+
goto error;
770+
759771
return commit_creds(new);
760772

761773
error:
@@ -862,7 +874,8 @@ long __sys_setfsgid(gid_t gid)
862874
ns_capable(old->user_ns, CAP_SETGID)) {
863875
if (!gid_eq(kgid, old->fsgid)) {
864876
new->fsgid = kgid;
865-
goto change_okay;
877+
if (security_task_fix_setgid(new,old,LSM_SETID_FS) == 0)
878+
goto change_okay;
866879
}
867880
}
868881

security/security.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,12 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old,
16961696
return call_int_hook(task_fix_setuid, 0, new, old, flags);
16971697
}
16981698

1699+
int security_task_fix_setgid(struct cred *new, const struct cred *old,
1700+
int flags)
1701+
{
1702+
return call_int_hook(task_fix_setgid, 0, new, old, flags);
1703+
}
1704+
16991705
int security_task_setpgid(struct task_struct *p, pid_t pgid)
17001706
{
17011707
return call_int_hook(task_setpgid, 0, p, pgid);

0 commit comments

Comments
 (0)