This patch adds a ctl_table_set per ipc namespace, and also the^^ sysctls
set_ownership() and permissions() callbacks for the new ctl_table_root
for ipc mqueue syscgtls.
...
Signed-off-by: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx>
---
+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;
+ 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;
+}