[CRIU] [PATCH 2/2] ipc: restore IPC objects credentials
Kinsbursky Stanislav
skinsbursky at openvz.org
Thu Jan 17 04:40:51 EST 2013
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
This part was lost after update to "sysctl" interface for IPC object ID
specifying (previous, currently obsolete, interface was able to pass proper
credentials with KEY change) .
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
ipc_ns.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
-------------- next part --------------
diff --git a/ipc_ns.c b/ipc_ns.c
index 12d0198..8717126 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -549,6 +549,7 @@ static int prepare_ipc_sem_desc(int fd, const IpcSemEntry *sem)
{ "kernel/sem_next_id", &sem->desc->id, CTL_U32 },
{ },
};
+ struct semid_ds semid;
ret = sysctl_op(req, CTL_WRITE);
if (ret < 0) {
@@ -569,6 +570,21 @@ static int prepare_ipc_sem_desc(int fd, const IpcSemEntry *sem)
return -EFAULT;
}
+ ret = semctl(id, sem->nsems, IPC_STAT, &semid);
+ if (ret == -1) {
+ pr_err("Failed to get sem stat structure\n");
+ return -EFAULT;
+ }
+
+ semid.sem_perm.uid = sem->desc->uid;
+ semid.sem_perm.gid = sem->desc->gid;
+
+ ret = semctl(id, sem->nsems, IPC_SET, &semid);
+ if (ret == -1) {
+ pr_err("Failed to set sem uid and gid\n");
+ return -EFAULT;
+ }
+
ret = prepare_ipc_sem_values(fd, sem);
if (ret < 0) {
pr_err("Failed to update sem pages\n");
@@ -667,6 +683,7 @@ static int prepare_ipc_msg_queue(int fd, const IpcMsgEntry *msq)
{ "kernel/msg_next_id", &msq->desc->id, CTL_U32 },
{ },
};
+ struct msqid_ds msqid;
ret = sysctl_op(req, CTL_WRITE);
if (ret < 0) {
@@ -686,6 +703,21 @@ static int prepare_ipc_msg_queue(int fd, const IpcMsgEntry *msq)
return -EFAULT;
}
+ ret = msgctl(id, IPC_STAT, &msqid);
+ if (ret == -1) {
+ pr_err("Failed to get msq stat structure\n");
+ return -EFAULT;
+ }
+
+ msqid.msg_perm.uid = msq->desc->uid;
+ msqid.msg_perm.gid = msq->desc->gid;
+
+ ret = msgctl(id, IPC_SET, &msqid);
+ if (ret == -1) {
+ pr_err("Failed to set msq queue uid and gid\n");
+ return -EFAULT;
+ }
+
ret = prepare_ipc_msg_queue_messages(fd, msq);
if (ret < 0) {
pr_err("Failed to update message queue messages\n");
@@ -760,6 +792,7 @@ static int prepare_ipc_shm_seg(int fd, const IpcShmEntry *shm)
{ "kernel/shm_next_id", &shm->desc->id, CTL_U32 },
{ },
};
+ struct shmid_ds shmid;
ret = sysctl_op(req, CTL_WRITE);
if (ret < 0) {
@@ -780,6 +813,21 @@ static int prepare_ipc_shm_seg(int fd, const IpcShmEntry *shm)
return -EFAULT;
}
+ ret = shmctl(id, IPC_STAT, &shmid);
+ if (ret == -1) {
+ pr_err("Failed to get shm stat structure\n");
+ return -EFAULT;
+ }
+
+ shmid.shm_perm.uid = shm->desc->uid;
+ shmid.shm_perm.gid = shm->desc->gid;
+
+ ret = shmctl(id, IPC_SET, &shmid);
+ if (ret == -1) {
+ pr_err("Failed to set shm uid and gid\n");
+ return -EFAULT;
+ }
+
ret = prepare_ipc_shm_pages(fd, shm);
if (ret < 0) {
pr_err("Failed to update shm pages\n");
More information about the CRIU
mailing list