mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
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. This patch was sent to the security mailing list and there were no objections. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgvWslnM+qUy+sgVg5n2WYw6TPBAFAl7mZCoACgkQ5n2WYw6T PBAk1RAAl8t3/m3lELf8qIir4OAd4nK0kc4e+7W8WkznX2ljUl2IetlNxDCBmEXr T5qoW6uPsr6kl5AKnbl9Ii7WpW/halsslpKSUNQCs6zbecoVdxekJ8ISW7xHuboZ SvS1bqm+t++PM0c0nWSFEr7eXYmPH8OGbCqu6/+nnbxPZf2rJX03e5LnHkEFDFnZ 0D/rsKgzMt01pdBJQXeoKk79etHO5MjuAkkYVEKJKCR1fM16lk7ECaCp0KJv1Mmx I88VncbLvI+um4t82d1Z8qDr2iLgogjJrMZC4WKfxDTmlmxox2Fz9ZJo+8sIWk6k T3a95x0s/mYCO4gWtpCVICt9+71Z3ie9T2iaI+CIe/kJvI/ysb+7LSkF+PD33bdz 0yv6Y9+VMRdzb3pW69R28IoP4wdYQOJRomsY49z6ypH0RgBWcBvyE6e4v+WJGRNK E164Imevf6rrZeqJ0kGSBS1nL9WmQHMaXabAwxg1jK1KRZD+YZj3EKC9S/+PAkaT 1qXUgvGuXHGjQrwU0hclQjgc6BAudWfAGdfrVr7IWwNKJmjgBf6C35my/azrkOg9 wHCEpUWVmZZLIZLM69/6QXdmMA+iR+rPz5qlVnWhWTfjRYJUXM455Zk+aNo+Qnwi +saCcdU+9xqreLeDIoYoebcV/ctHeW0XCQi/+ebjexXVlyeSfYs= =I+0L -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
4a87b197c1
@ -191,6 +191,8 @@ LSM_HOOK(int, 0, kernel_post_read_file, struct file *file, char *buf,
|
||||
loff_t size, enum kernel_read_file_id id)
|
||||
LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old,
|
||||
int flags)
|
||||
LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old,
|
||||
int flags)
|
||||
LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid)
|
||||
LSM_HOOK(int, 0, task_getpgid, struct task_struct *p)
|
||||
LSM_HOOK(int, 0, task_getsid, struct task_struct *p)
|
||||
|
@ -659,6 +659,15 @@
|
||||
* @old is the set of credentials that are being replaces
|
||||
* @flags contains one of the LSM_SETID_* values.
|
||||
* Return 0 on success.
|
||||
* @task_fix_setgid:
|
||||
* Update the module's state after setting one or more of the group
|
||||
* identity attributes of the current process. The @flags parameter
|
||||
* indicates which of the set*gid system calls invoked this hook.
|
||||
* @new is the set of credentials that will be installed. Modifications
|
||||
* should be made to this rather than to @current->cred.
|
||||
* @old is the set of credentials that are being replaced.
|
||||
* @flags contains one of the LSM_SETID_* values.
|
||||
* Return 0 on success.
|
||||
* @task_setpgid:
|
||||
* Check permission before setting the process group identifier of the
|
||||
* process @p to @pgid.
|
||||
|
@ -392,6 +392,8 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
|
||||
enum kernel_read_file_id id);
|
||||
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
||||
int flags);
|
||||
int security_task_fix_setgid(struct cred *new, const struct cred *old,
|
||||
int flags);
|
||||
int security_task_setpgid(struct task_struct *p, pid_t pgid);
|
||||
int security_task_getpgid(struct task_struct *p);
|
||||
int security_task_getsid(struct task_struct *p);
|
||||
@ -1036,6 +1038,13 @@ static inline int security_task_fix_setuid(struct cred *new,
|
||||
return cap_task_fix_setuid(new, old, flags);
|
||||
}
|
||||
|
||||
static inline int security_task_fix_setgid(struct cred *new,
|
||||
const struct cred *old,
|
||||
int flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
|
||||
{
|
||||
return 0;
|
||||
|
15
kernel/sys.c
15
kernel/sys.c
@ -393,6 +393,10 @@ long __sys_setregid(gid_t rgid, gid_t egid)
|
||||
new->sgid = new->egid;
|
||||
new->fsgid = new->egid;
|
||||
|
||||
retval = security_task_fix_setgid(new, old, LSM_SETID_RE);
|
||||
if (retval < 0)
|
||||
goto error;
|
||||
|
||||
return commit_creds(new);
|
||||
|
||||
error:
|
||||
@ -435,6 +439,10 @@ long __sys_setgid(gid_t gid)
|
||||
else
|
||||
goto error;
|
||||
|
||||
retval = security_task_fix_setgid(new, old, LSM_SETID_ID);
|
||||
if (retval < 0)
|
||||
goto error;
|
||||
|
||||
return commit_creds(new);
|
||||
|
||||
error:
|
||||
@ -756,6 +764,10 @@ long __sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
|
||||
new->sgid = ksgid;
|
||||
new->fsgid = new->egid;
|
||||
|
||||
retval = security_task_fix_setgid(new, old, LSM_SETID_RES);
|
||||
if (retval < 0)
|
||||
goto error;
|
||||
|
||||
return commit_creds(new);
|
||||
|
||||
error:
|
||||
@ -862,7 +874,8 @@ long __sys_setfsgid(gid_t gid)
|
||||
ns_capable(old->user_ns, CAP_SETGID)) {
|
||||
if (!gid_eq(kgid, old->fsgid)) {
|
||||
new->fsgid = kgid;
|
||||
goto change_okay;
|
||||
if (security_task_fix_setgid(new,old,LSM_SETID_FS) == 0)
|
||||
goto change_okay;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1696,6 +1696,12 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
||||
return call_int_hook(task_fix_setuid, 0, new, old, flags);
|
||||
}
|
||||
|
||||
int security_task_fix_setgid(struct cred *new, const struct cred *old,
|
||||
int flags)
|
||||
{
|
||||
return call_int_hook(task_fix_setgid, 0, new, old, flags);
|
||||
}
|
||||
|
||||
int security_task_setpgid(struct task_struct *p, pid_t pgid)
|
||||
{
|
||||
return call_int_hook(task_setpgid, 0, p, pgid);
|
||||
|
Loading…
Reference in New Issue
Block a user