lkml.org 
[lkml]   [2021]   [Jul]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] ipc: add set_ownership() and permissions() callbacks for posix mqueue sysctl
On 2021-07-28 20:06, cgel.zte@gmail.com wrote:
> This patch adds a ctl_table_set per ipc namespace, and also the
> set_ownership() and permissions() callbacks for the new ctl_table_root
> for ipc mqueue syscgtls.
^^ sysctls

This makes sense to me, just some nits below.

Acked-by: Davidlohr Bueso <dbueso@suse.de>

>
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
...
> +static int set_permissions(struct ctl_table_header *head,
> + struct ctl_table *table)
> +{
> + struct ipc_namespace *ipc_ns =
> + container_of(head->set, struct ipc_namespace, mq_set);
> + struct user_namespace *user_ns = ipc_ns->user_ns;
> + int mode;
> +
> + /* Allow users with CAP_SYS_RESOURCE unrestrained access */
> + if (ns_capable(user_ns, CAP_SYS_RESOURCE))
> + mode = (table->mode & S_IRWXU) >> 6;
> + else
> + /* Allow all others at most read-only access */
> + mode = table->mode & S_IROTH;

Please use curly braces for the else.

> + return (mode << 6) | (mode << 3) | mode;
> +}
> +
> +static void set_ownership(struct ctl_table_header *head,
> + struct ctl_table *table,
> + kuid_t *uid, kgid_t *gid)
> +{
> + struct ipc_namespace *ipc_ns =
> + container_of(head->set, struct ipc_namespace, mq_set);
> + struct user_namespace *user_ns = ipc_ns->user_ns;
> + kuid_t ns_root_uid;
> + kgid_t ns_root_gid;
> +
> + ns_root_uid = make_kuid(user_ns, 0);
> + if (uid_valid(ns_root_uid))
> + *uid = ns_root_uid;
> +
> + ns_root_gid = make_kgid(user_ns, 0);
> + if (gid_valid(ns_root_gid))
> + *gid = ns_root_gid;
> +}

Could set_permissions() and set_ownership() be factored such that we can
avoid duplicated code between ipc and net ns? Something like:

void set_permissions(struct ctl_table_header *head, struct ctl_table
*table)
{
struct ipc_namespace *ipc_ns = container_of(head->set, struct
ipc_namespace, mq_set);
set_permissions_common(ipc_ns->user_ns);
}

Thanks,
Davidlohr

\
 
 \ /
  Last update: 2021-07-30 17:10    [W:0.274 / U:1.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site