IPC: checkpoint/restore in userspace enhancements
Subsystems (6)
v6 cover IPC: checkpoint/restore in userspace enhancements
v6:
1) rebased on 3.7-rc1
v5:
1) Several define-dependent compile bugs fixed
2) IPC message copy test updated
3) A couple of minor fixes.
4) Qlogic driver update: rename of its internal SEM_SET define into SEM_INIT (compile error).
v4:
1) If MSG_COPY flag is specified, then "mtype" is not a type, but message number to copy.
2) MSG_SET_COPY logic for sys_msgctl() was removed.
v3:
1) Copy messages to user-space under spinlock was replaced by allocation of dummy message before queue lock and then copy of desired message to the dummy one instead of unlinking it from queue list.
I.e. the message queue copy logic was changed: messages can be retrived one by one (instead of receiving of the whole list at once).
This patch set is aimed to provide additional functionality for all IPC objects,
which is required for migration of these objects by user-space checkpoint/restore utils (CRIU).
The main problem here was impossibility to set up object id. This patch set solves the problem in two steps:
1) Makes it possible to create new object (shared memory, semaphores set or messages queue) with ID, equal to passed key.
2) Makes it possible to change existent object key.
Another problem was to peek messages from queues without deleting them. This was achived by introducing of new MSG_COPY flag for sys_msgrcv(). If MSG_COPY flag is set, then msgtyp is interpreted as message number.
The following series implements...
---
Stanislav Kinsbursky (10):
ipc: remove forced assignment of selected message
ipc: "use key as id" functionality for resource get system call introduced
ipc: segment key change helper introduced
ipc: add new SHM_SET command for sys_shmctl() call
ipc: add new MSG_SET command for sys_msgctl() call
glge driver: rename internal SEM_SET macro to SEM_INIT
ipc: add new SEM_SET command for sys_semctl() call
IPC: message queue receive cleanup
IPC: message queue copy feature introduced
test: IPC message queue copy feture test
drivers/net/ethernet/qlogic/qlge/qlge.h | 4 drivers/net/ethernet/qlogic/qlge/qlge_main.c | 16 +- include/linux/msg.h | 5 - include/uapi/linux/ipc.h | 1 include/uapi/linux/msg.h | 2 include/uapi/linux/sem.h | 1 include/uapi/linux/shm.h | 1 ipc/compat.c | 45 +++-- ipc/msg.c | 116 +++++++++--- ipc/msgutil.c | 38 ++++ ipc/sem.c | 14 + ipc/shm.c | 17 +- ipc/util.c | 69 +++++++ ipc/util.h | 6 + security/selinux/hooks.c | 3 security/smack/smack_lsm.c | 3 tools/testing/selftests/ipc/Makefile | 28 +++ tools/testing/selftests/ipc/msgque.c | 251 ++++++++++++++++++++++++++ 18 files changed, 548 insertions(+), 72 deletions(-) create mode 100644 tools/testing/selftests/ipc/Makefile create mode 100644 tools/testing/selftests/ipc/msgque.c
PATCH v6 1/10 ipc: remove forced assignment of selected message
This is a cleanup patch. The assignment is redundant.
--- ipc/msg.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
ipc/msg.c +1 -4
@@ -793,12 +793,9 @@ long do_msgrcv(int msqid, long *pmtype, void __user *mtext, msg = walk_msg;if (mode ==SEARCH_LESSEQUAL && walk_msg->m_type !=1 ) { - msg = walk_msg; msgtyp = walk_msg->m_type -1 ; - }else { - msg = walk_msg; + }else break ; - } } tmp = tmp->next; }
Re: [PATCH v6 01/10] ipc: remove forced assignment of selected message
Quoted 3 lines · Stanislav Kinsbursky
This is a cleanup patch. The assignment is redundant.
Signed-off-by Stanislav Kinsbursky <[email protected]>
Quoted 27 lines
--- ipc/msg.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)ipc/msg.c +1
-5@@ -793,12 +793,9 @@ long do_msgrcv(int msqid, long *pmtype, void __user *mtext, msg = walk_msg;if (mode ==SEARCH_LESSEQUAL && walk_msg->m_type !=1 ) { - msg = walk_msg; msgtyp = walk_msg->m_type -1 ; - }else { - msg = walk_msg; + }else break ; - } } tmp = tmp->next; } --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 2/10 ipc: "use key as id" functionality for resource get system call introduced
In reply to Stanislav KinsburskyThis patch introduces new IPC resource get request flag IPC_PRESET, which should be interpreted as a request to try to allocate IPC slot with number, starting from value resented by key. IOW, kernel will try allocate new segment in specified slot.
Note: if desired slot is not emply, then next free slot will be used.
--- include/uapi/linux/ipc.h | 1 + ipc/msg.c | 4 +++- ipc/sem.c | 4 +++- ipc/shm.c | 4 +++- ipc/util.c | 18 +++++++++++++++--- ipc/util.h | 3 ++- 6 files changed, 27 insertions(+), 7 deletions(-)
include/uapi/linux/ipc.h +1 -0
@@ -24,6 +24,7 @@ struct ipc_perm#define IPC_CREAT 00001000/* create if key is nonexistent */ #define IPC_EXCL 00002000/* fail if key exists */ #define IPC_NOWAIT 00004000/* return error on wait */ +#define IPC_PRESET 00040000/* use key as id */ /* these fields are used by the DIPC package so the kernel as standard should avoid using them if possible */
ipc/msg.c +3 -1
@@ -190,6 +190,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params) msq->q_perm.mode = msgflg &S_IRWXUGO ; msq->q_perm.key = key; + msq->q_perm.id = (msgflg &IPC_PRESET ) ? key :0 ; msq->q_perm.security =NULL ; retval =security_msg_queue_alloc (msq);
@@ -201,7 +202,8 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)/* * ipc_addid() locks msq */ - id =ipc_addid (&msg_ids (ns), &msq->q_perm, ns->msg_ctlmni); + id =ipc_addid (&msg_ids (ns), &msq->q_perm, ns->msg_ctlmni, + msgflg &IPC_PRESET );if (id <0 ) {security_msg_queue_free (msq);ipc_rcu_putref (msq);
ipc/sem.c +3 -1
@@ -306,6 +306,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params) sma->sem_perm.mode = (semflg &S_IRWXUGO ); sma->sem_perm.key = key; + sma->sem_perm.id = (semflg &IPC_PRESET ) ? key :0 ; sma->sem_perm.security =NULL ; retval =security_sem_alloc (sma);
@@ -314,7 +315,8 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)return retval; } - id =ipc_addid (&sem_ids (ns), &sma->sem_perm, ns->sc_semmni); + id =ipc_addid (&sem_ids (ns), &sma->sem_perm, ns->sc_semmni, + semflg &IPC_PRESET );if (id <0 ) {security_sem_free (sma);ipc_rcu_putref (sma);
ipc/shm.c +3 -1
@@ -480,6 +480,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) shp->shm_perm.key = key; shp->shm_perm.mode = (shmflg &S_IRWXUGO ); + shp->shm_perm.id = (shmflg &IPC_PRESET ) ? key :0 ; shp->mlock_user =NULL ; shp->shm_perm.security =NULL ;
@@ -510,7 +511,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)if (IS_ERR (file)) goto no_file; - id =ipc_addid (&shm_ids (ns), &shp->shm_perm, ns->shm_ctlmni); + id =ipc_addid (&shm_ids (ns), &shp->shm_perm, ns->shm_ctlmni, + shmflg &IPC_PRESET );if (id <0 ) { error = id; goto no_id;
ipc/util.c +15 -3
@@ -238,16 +238,22 @@ int ipc_get_maxid(struct ipc_ids *ids)* @ids: IPC identifier set * @new: new IPC permission set * @size: limit for the number of used ids +* @preset: use passed new->id value as desired id * * Add an entry 'new' to the IPC ids idr. The permissions object is * initialised and the first free entry is set up and the id assigned * is returned. The 'new' entry is returned in a locked state on success. * On failure the entry is not locked and a negative err-code is returned. * +* If 'preset' is set, then passed new->id is desired to be set for new +* segment. And allocated id is equal to passed value, then ipc ids will +* left unchanged and new->seq will be updated to correspond specified id value. +* * Called with ipc_ids.rw_mutex held as a writer. */ -int ipc_addid (struct ipc_ids * ids,struct kern_ipc_perm * new,int size) +int ipc_addid (struct ipc_ids * ids,struct kern_ipc_perm * new,int size, +int preset) {kuid_t euid;kgid_t egid;
@@ -264,7 +270,8 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)rcu_read_lock ();spin_lock (&new->lock); - err =idr_get_new (&ids->ipcs_idr, new, &id); + err =idr_get_new_above (&ids->ipcs_idr, new, +ipcid_to_idx (new->id), &id);if (err) {spin_unlock (&new->lock);rcu_read_unlock ();
@@ -277,6 +284,11 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) new->cuid = new->uid = euid; new->gid = new->cgid = egid; +if (preset &&ipcid_to_idx (new->id) == id) { + new->seq =ipcid_to_seq (new->id); +return id; + } + new->seq = ids->seq++;if (ids->seq > ids->seq_max) ids->seq =0 ;
@@ -736,7 +748,7 @@ struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id)int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids,struct ipc_ops *ops,struct ipc_params *params) { -if (params->key ==IPC_PRIVATE ) +if (params->key ==IPC_PRIVATE && ((params->flg &IPC_PRESET ) ==0 ))return ipcget_new (ns, ids, ops, params);else return ipcget_public (ns, ids, ops, params);
ipc/util.h +2 -1
@@ -92,9 +92,10 @@ void __init ipc_init_proc_interface(const char *path, const char *header,#define IPC_SHM_IDS 2#define ipcid_to_idx (id) ((id) % SEQ_MULTIPLIER) +#define ipcid_to_seq (id) ((id) / SEQ_MULTIPLIER)/* must be called with ids->rw_mutex acquired for writing */ -int ipc_addid (struct ipc_ids *,struct kern_ipc_perm *,int ); +int ipc_addid (struct ipc_ids *,struct kern_ipc_perm *,int ,int );/* must be called with ids->rw_mutex acquired for reading */ int ipc_get_maxid (struct ipc_ids *);
Re: [PATCH v6 02/10] ipc: "use key as id" functionality for resource get system call introduced
Quoted 6 lines · Stanislav Kinsbursky
This patch introduces new IPC resource get request flag
IPC_PRESET, which should be interpreted as a request to try to allocate IPC slot with number, starting from value resented by key. IOW, kernel will try allocate new segment in specified slot.Note: if desired slot is not emply, then next free slot will be used.
This way of handling things is pretty nasty.
- You don't fail if the requested id is not available.
- You don't allow assigning the key (which leads to the need to change the key in later patches). Changing the creator uid and creator gid and key is semantically ugly.
It would be much cleaner if you could instead add IPC_PRESET and then extend the definition of the creation functions all by one argument.
aka
int msgget(key_t key, int msgflg, int id);
int semget(key_t key, int nsems, int semflg, int id); int shmget(key_t key, size_t size, int shmflg, int id);
Where the extra id argument is ignored unless IPC_PRESET is specified.
Also msgget, semget, and shmget should fail if unregconized flags are passed in. That ipcget doesn't do that today is bizarre.
Eric
Re: [PATCH v6 02/10] ipc: "use key as id" functionality for resource get system call introduced
Quoted 24 lines · [email protected] (Eric W. Biederman) writes:
Quoted 6 lines · Stanislav Kinsbursky
This patch introduces new IPC resource get request flag
IPC_PRESET, which should be interpreted as a request to try to allocate IPC slot with number, starting from value resented by key. IOW, kernel will try allocate new segment in specified slot.Note: if desired slot is not emply, then next free slot will be used.
This way of handling things is pretty nasty.
- You don't fail if the requested id is not available.
- You don't allow assigning the key (which leads to the need to change the key in later patches). Changing the creator uid and creator gid and key is semantically ugly.It would be much cleaner if you could instead add
IPC_PRESETand then extend the definition of the creation functions all by one argument.aka
intmsgget(key_t key, int msgflg, int id);
intsemget(key_t key, int nsems, int semflg, int id); intshmget(key_t key, size_t size, int shmflg, int id);
Quoted 4 lines
Where the extra id argument is ignored unless
IPC_PRESETis specified.Also msgget, semget, and shmget should fail if unregconized flags are passed in. That ipcget doesn't do that today is bizarre.
Hmm. Come to think of it I don't see why you need to set the id at all. We are using an idr allocator which effectively offers the semantics that the lowest available id will be allocated. The same semantics we have for file descriptors.
So it should be possible at least for the first pass at checkpoint/restart to implement the restoration of sysv ipc without IPC_PRESET at all.
So IPC_PRESET should just be an optimization, not a necessary feature.
That makes all of your code go away except the message queue peeking, which seems much less intrusive for the first pass.
Eric
PATCH v6 3/10 ipc: segment key change helper introduced
In reply to Stanislav KinsburskyThis patch introduces existent segment key changing infrastructure. New function ipc_update_key() can be used change segment key, cuid, cgid values. It checks for that new key is not used (except IPC_PRIVATE) prior to set it on existent.
To make this possible, added copying of this fields from user-space in __get_compat_ipc_perm() and __get_compat_ipc64_perm() functions. Also segment search by key and lock were splitted into different functions, because ipc_update_key() doesn't need to lock the segment during check that new key is not used.
--- ipc/compat.c | 6 ++++++ ipc/util.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- ipc/util.h | 2 ++ 3 files changed, 56 insertions(+), 3 deletions(-)
ipc/compat.c +6 -0
@@ -144,6 +144,9 @@ static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64, err =__get_user (p64->uid, &up64->uid); err |=__get_user (p64->gid, &up64->gid); err |=__get_user (p64->mode, &up64->mode); + err |=__get_user (p64->cuid, &up64->cuid); + err |=__get_user (p64->cgid, &up64->cgid); + err |=__get_user (p64->key, &up64->key);return err; }
@@ -155,6 +158,9 @@ static inline int __get_compat_ipc_perm(struct ipc64_perm *p, err =__get_user (p->uid, &up->uid); err |=__get_user (p->gid, &up->gid); err |=__get_user (p->mode, &up->mode); + err |=__get_user (p->cuid, &up->cuid); + err |=__get_user (p->cgid, &up->cgid); + err |=__get_user (p->key, &up->key);return err; }
ipc/util.c +48 -3
81 lines not on this page · raw message
ipc/util.h +2 -0
@@ -126,6 +126,8 @@ struct kern_ipc_perm *ipc_lock(struct ipc_ids *, int);void kernel_to_ipc64_perm (struct kern_ipc_perm *in,struct ipc64_perm *out);void ipc64_perm_to_ipc_perm (struct ipc64_perm *in,struct ipc_perm *out); +int ipc_update_key (struct ipc_ids *ids,struct ipc64_perm *in, +struct kern_ipc_perm *out);int ipc_update_perm (struct ipc64_perm *in,struct kern_ipc_perm *out); struct kern_ipc_perm *ipcctl_pre_down(struct ipc_namespace *ns, struct ipc_ids *ids, int id, int cmd,
Re: [PATCH v6 03/10] ipc: segment key change helper introduced
Quoted 11 lines · Stanislav Kinsbursky
This patch introduces existent segment key changing infrastructure. New function
ipc_update_key()can be used change segment key, cuid, cgid values. It checks for that new key is not used (exceptIPC_PRIVATE) prior to set it on existent.
To make this possible, added copying of this fields from user-space in__get_compat_ipc_perm()and__get_compat_ipc64_perm()functions. Also segment search by key and lock were splitted into different functions, becauseipc_update_key()doesn't need to lock the segment during check that new key is not used.Signed-off-by Stanislav Kinsbursky <[email protected]>
Quoted 138 lines
--- ipc/compat.c | 6 ++++++ ipc/util.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- ipc/util.h | 2 ++ 3 files changed, 56 insertions(+), 3 deletions(-)ipc/compat.c +6
-0@@ -144,6 +144,9 @@ static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64, err =__get_user (p64->uid, &up64->uid); err |=__get_user (p64->gid, &up64->gid); err |=__get_user (p64->mode, &up64->mode); + err |=__get_user (p64->cuid, &up64->cuid); + err |=__get_user (p64->cgid, &up64->cgid); + err |=__get_user (p64->key, &up64->key);return err; }@@ -155,6 +158,9 @@ static inline int __get_compat_ipc_perm(struct ipc64_perm *p, err =__get_user (p->uid, &up->uid); err |=__get_user (p->gid, &up->gid); err |=__get_user (p->mode, &up->mode); + err |=__get_user (p->cuid, &up->cuid); + err |=__get_user (p->cgid, &up->cgid); + err |=__get_user (p->key, &up->key);return err; }ipc/util.c +48
-3@@ -173,7 +173,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header,* @key: The key to find * * Requires ipc_ids.rw_mutex locked. -* Returns the LOCKED pointer to the ipc structure if found or NULL +* Returns the UNLOCKED pointer to the ipc structure if found or NULL * if not. * If key is found ipc points to the owning ipc structure */ @@ -195,7 +195,6 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key)continue ; } -ipc_lock_by_ptr (ipc);return ipc; }@@ -203,6 +202,27 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key) }/** +* ipc_findkey_locked - find and lock a key in an ipc identifier set +* @ids: Identifier set +* @key: The key to find +* +* Requires ipc_ids.rw_mutex locked. +* Returns the LOCKED pointer to the ipc structure if found or NULL +* if not. +* If key is found ipc points to the owning ipc structure +*/ + +static struct kern_ipc_perm *ipc_findkey_locked (struct ipc_ids *ids,key_t key) +{ +struct kern_ipc_perm *ipc; + + ipc =ipc_findkey (ids, key); +if (ipc) +ipc_lock_by_ptr (ipc); +return ipc; +} + +/** * ipc_get_maxid - get the last assigned id * @ids: IPC identifier set * @@ -388,7 +408,7 @@ retry:* a new entry + read locks are not "upgradable" */ down_write (&ids->rw_mutex); - ipcp =ipc_findkey (ids, params->key); + ipcp =ipc_findkey_locked (ids, params->key);if (ipcp ==NULL ) {/* key not used */ if (!(flg &IPC_CREAT ))@@ -755,6 +775,31 @@ int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids, }/** +* ipc_update_key - update the key of an IPC. +* @in: the permission given as input. +* @out: the permission of the ipc to set. +* +* Common routine called by sys_shmctl(), sys_semctl(). sys_msgctl(). +*/ +int ipc_update_key (struct ipc_ids *ids,struct ipc64_perm *in, +struct kern_ipc_perm *out) +{ + +if (in->key && out->key != in->key) { +/* +* Check for existent segment with the same key. +* Note: ipc_ids.rw_mutex is taken for write already. +*/ +if (ipc_findkey (ids, in->key)) +return -EEXIST ; + } + out->cuid = in->cuid; + out->cgid = in->cgid; + out->key = in->key; +return 0 ; +} + +/** * ipc_update_perm - update the permissions of an IPC. * @in: the permission given as input. * @out: the permission of the ipc to set. ipc/util.h +2
-1@@ -126,6 +126,8 @@ struct kern_ipc_perm *ipc_lock(struct ipc_ids *, int);void kernel_to_ipc64_perm (struct kern_ipc_perm *in,struct ipc64_perm *out);void ipc64_perm_to_ipc_perm (struct ipc64_perm *in,struct ipc_perm *out); +int ipc_update_key (struct ipc_ids *ids,struct ipc64_perm *in, +struct kern_ipc_perm *out);int ipc_update_perm (struct ipc64_perm *in,struct kern_ipc_perm *out); struct kern_ipc_perm *ipcctl_pre_down(struct ipc_namespace *ns, struct ipc_ids *ids, int id, int cmd, --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 4/10 ipc: add new SHM_SET command for sys_shmctl() call
In reply to Stanislav KinsburskyNew SHM_SET command will be interpreted exactly as IPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise -EEXIST is returned.
--- include/uapi/linux/shm.h | 1 + ipc/compat.c | 1 + ipc/shm.c | 13 +++++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 15 insertions(+), 2 deletions(-)
include/uapi/linux/shm.h +1 -0
@@ -56,6 +56,7 @@ struct shmid_ds {/* ipcs ctl commands */ #define SHM_STAT 13#define SHM_INFO 14 +#define SHM_SET 15/* Obsolete, used only for backwards compatibility */ struct shminfo {
ipc/compat.c +1 -0
@@ -692,6 +692,7 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)case IPC_SET : +case SHM_SET :if (version ==IPC_64 ) { err =get_compat_shmid64_ds (&s64, uptr); }else {
ipc/shm.c +11 -2
@@ -636,6 +636,9 @@ copy_shmid_from_user(struct shmid64_ds *out, void __user *buf, int version) out->shm_perm.uid = tbuf_old.shm_perm.uid; out->shm_perm.gid = tbuf_old.shm_perm.gid; out->shm_perm.mode = tbuf_old.shm_perm.mode; + out->shm_perm.cuid = tbuf_old.shm_perm.cuid; + out->shm_perm.cgid = tbuf_old.shm_perm.cgid; + out->shm_perm.key = tbuf_old.shm_perm.key;return 0 ; }
@@ -740,12 +743,13 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,struct shmid_kernel *shp;int err; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==SHM_SET ) {if (copy_shmid_from_user (&shmid64, buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &shm_ids (ns), shmid, cmd, + ipcp =ipcctl_pre_down (ns, &shm_ids (ns), shmid, + (cmd !=SHM_SET ) ? cmd :IPC_SET , &shmid64.shm_perm,0 );if (IS_ERR (ipcp))return PTR_ERR (ipcp);
@@ -759,6 +763,10 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,case IPC_RMID :do_shm_rmid (ns, ipcp); goto out_up; +case SHM_SET : + err =ipc_update_key (&shm_ids (ns), &shmid64.shm_perm, ipcp); +if (err) +break ;case IPC_SET : err =ipc_update_perm (&shmid64.shm_perm, ipcp);if (err)
@@ -938,6 +946,7 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf) }case IPC_RMID :case IPC_SET : +case SHM_SET : err =shmctl_down (ns, shmid, cmd, buf, version);return err;default :
security/selinux/hooks.c +1 -0
@@ -5027,6 +5027,7 @@ static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd) perms =SHM__GETATTR |SHM__ASSOCIATE ;break ;case IPC_SET : +case SHM_SET : perms =SHM__SETATTR ;break ;case SHM_LOCK :
security/smack/smack_lsm.c +1 -0
@@ -2121,6 +2121,7 @@ static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd) may =MAY_READ ;break ;case IPC_SET : +case SHM_SET :case SHM_LOCK :case SHM_UNLOCK :case IPC_RMID :
Re: [PATCH v6 04/10] ipc: add new SHM_SET command for sys_shmctl() call
Quoted 4 lines · Stanislav Kinsbursky
New
SHM_SETcommand will be interpreted exactly asIPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise-EEXISTis returned.
[...]
Quoted 2 lines
ipc/shm.c +0
-0
[...]
ipc/shm.c static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, · line 769
Quoted 8 lines
ipc/shm.c +4
-0@@ -759,6 +763,10 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,case IPC_RMID :do_shm_rmid (ns, ipcp); goto out_up; +case SHM_SET : + err =ipc_update_key (&shm_ids (ns), &shmid64.shm_perm, ipcp); +if (err) +break ;
[...]
Please add /* fall through */ here, and in the similar cases in patches 5 and 7, to make clear that it's deliberate.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v6 04/10] ipc: add new SHM_SET command for sys_shmctl() call
In reply to Stanislav KinsburskyQuoted 6 lines · Stanislav Kinsbursky
New
SHM_SETcommand will be interpreted exactly asIPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise-EEXISTis returned.Signed-off-by Stanislav Kinsbursky <[email protected]>
Looks sane (modulo 'fallsthrough' comment already requested)
Quoted 110 lines
--- include/uapi/linux/shm.h | 1 + ipc/compat.c | 1 + ipc/shm.c | 13 +++++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 15 insertions(+), 2 deletions(-)include/uapi/linux/shm.h +1
-0@@ -56,6 +56,7 @@ struct shmid_ds {/* ipcs ctl commands */ #define SHM_STAT 13#define SHM_INFO 14 +#define SHM_SET 15/* Obsolete, used only for backwards compatibility */ struct shminfo {ipc/compat.c +1
-0@@ -692,6 +692,7 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)case IPC_SET : +case SHM_SET :if (version ==IPC_64 ) { err =get_compat_shmid64_ds (&s64, uptr); }else {ipc/shm.c +11
-2@@ -636,6 +636,9 @@ copy_shmid_from_user(struct shmid64_ds *out, void __user *buf, int version) out->shm_perm.uid = tbuf_old.shm_perm.uid; out->shm_perm.gid = tbuf_old.shm_perm.gid; out->shm_perm.mode = tbuf_old.shm_perm.mode; + out->shm_perm.cuid = tbuf_old.shm_perm.cuid; + out->shm_perm.cgid = tbuf_old.shm_perm.cgid; + out->shm_perm.key = tbuf_old.shm_perm.key;return 0 ; }@@ -740,12 +743,13 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,struct shmid_kernel *shp;int err; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==SHM_SET ) {if (copy_shmid_from_user (&shmid64, buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &shm_ids (ns), shmid, cmd, + ipcp =ipcctl_pre_down (ns, &shm_ids (ns), shmid, + (cmd !=SHM_SET ) ? cmd :IPC_SET , &shmid64.shm_perm,0 );if (IS_ERR (ipcp))return PTR_ERR (ipcp);@@ -759,6 +763,10 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,case IPC_RMID :do_shm_rmid (ns, ipcp); goto out_up; +case SHM_SET : + err =ipc_update_key (&shm_ids (ns), &shmid64.shm_perm, ipcp); +if (err) +break ;case IPC_SET : err =ipc_update_perm (&shmid64.shm_perm, ipcp);if (err)@@ -938,6 +946,7 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf) }case IPC_RMID :case IPC_SET : +case SHM_SET : err =shmctl_down (ns, shmid, cmd, buf, version);return err;default :security/selinux/hooks.c +1
-0@@ -5027,6 +5027,7 @@ static int selinux_shm_shmctl(struct shmid_kernel *shp, int cmd) perms =SHM__GETATTR |SHM__ASSOCIATE ;break ;case IPC_SET : +case SHM_SET : perms =SHM__SETATTR ;break ;case SHM_LOCK :security/smack/smack_lsm.c +1
-1@@ -2121,6 +2121,7 @@ static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd) may =MAY_READ ;break ;case IPC_SET : +case SHM_SET :case SHM_LOCK :case SHM_UNLOCK :case IPC_RMID : --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 5/10 ipc: add new MSG_SET command for sys_msgctl() call
In reply to Stanislav KinsburskyNew MSG_SET command will be interpreted exactly as IPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise -EEXIST is returned.
--- include/uapi/linux/msg.h | 1 + ipc/compat.c | 1 + ipc/msg.c | 13 +++++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 15 insertions(+), 2 deletions(-)
include/uapi/linux/msg.h +1 -0
@@ -6,6 +6,7 @@/* ipcs ctl commands */ #define MSG_STAT 11#define MSG_INFO 12 +#define MSG_SET 13/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */
ipc/compat.c +1 -0
@@ -483,6 +483,7 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)break ;case IPC_SET : +case MSG_SET :if (version ==IPC_64 ) { err =get_compat_msqid64 (&m64, uptr); }else {
ipc/msg.c +11 -2
@@ -392,6 +392,9 @@ copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) out->msg_perm.uid = tbuf_old.msg_perm.uid; out->msg_perm.gid = tbuf_old.msg_perm.gid; out->msg_perm.mode = tbuf_old.msg_perm.mode; + out->msg_perm.cuid = tbuf_old.msg_perm.cuid; + out->msg_perm.cgid = tbuf_old.msg_perm.cgid; + out->msg_perm.key = tbuf_old.msg_perm.key;if (tbuf_old.msg_qbytes ==0 ) out->msg_qbytes = tbuf_old.msg_lqbytes;
@@ -418,12 +421,13 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,struct msg_queue *msq;int err; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==MSG_SET ) {if (copy_msqid_from_user (&msqid64, buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &msg_ids (ns), msqid, cmd, + ipcp =ipcctl_pre_down (ns, &msg_ids (ns), msqid, + (cmd !=MSG_SET ) ? cmd :IPC_SET , &msqid64.msg_perm, msqid64.msg_qbytes);if (IS_ERR (ipcp))return PTR_ERR (ipcp);
@@ -439,6 +443,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,freeque (ns, ipcp); goto out_up;case IPC_SET : +case MSG_SET :if (msqid64.msg_qbytes > ns->msg_ctlmnb && !capable (CAP_SYS_RESOURCE )) { err = -EPERM ;
@@ -451,6 +456,9 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, msq->q_qbytes = msqid64.msg_qbytes; +if (cmd ==MSG_SET ) +ipc_update_key (&msg_ids (ns), &msqid64.msg_perm, ipcp); + msq->q_ctime =get_seconds ();/* sleeping receivers might be excluded by * stricter permissions.
@@ -569,6 +577,7 @@ SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf) }case IPC_SET :case IPC_RMID : +case MSG_SET : err =msgctl_down (ns, msqid, cmd, buf, version);return err;default :
security/selinux/hooks.c +1 -0
@@ -4885,6 +4885,7 @@ static int selinux_msg_queue_msgctl(struct msg_queue *msq, int cmd) perms =MSGQ__GETATTR |MSGQ__ASSOCIATE ;break ;case IPC_SET : +case MSG_SET : perms =MSGQ__SETATTR ;break ;case IPC_RMID :
security/smack/smack_lsm.c +1 -0
@@ -2374,6 +2374,7 @@ static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd) may =MAY_READ ;break ;case IPC_SET : +case MSG_SET :case IPC_RMID : may =MAY_READWRITE ;break ;
Re: [PATCH v6 05/10] ipc: add new MSG_SET command for sys_msgctl() call
Quoted 6 lines · Stanislav Kinsbursky
New
MSG_SETcommand will be interpreted exactly asIPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise-EEXISTis returned.Signed-off-by Stanislav Kinsbursky <[email protected]>
Quoted 117 lines
--- include/uapi/linux/msg.h | 1 + ipc/compat.c | 1 + ipc/msg.c | 13 +++++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 15 insertions(+), 2 deletions(-)include/uapi/linux/msg.h +1
-0@@ -6,6 +6,7 @@/* ipcs ctl commands */ #define MSG_STAT 11#define MSG_INFO 12 +#define MSG_SET 13/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */ ipc/compat.c +1
-0@@ -483,6 +483,7 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)break ;case IPC_SET : +case MSG_SET :if (version ==IPC_64 ) { err =get_compat_msqid64 (&m64, uptr); }else {ipc/msg.c +11
-2@@ -392,6 +392,9 @@ copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) out->msg_perm.uid = tbuf_old.msg_perm.uid; out->msg_perm.gid = tbuf_old.msg_perm.gid; out->msg_perm.mode = tbuf_old.msg_perm.mode; + out->msg_perm.cuid = tbuf_old.msg_perm.cuid; + out->msg_perm.cgid = tbuf_old.msg_perm.cgid; + out->msg_perm.key = tbuf_old.msg_perm.key;if (tbuf_old.msg_qbytes ==0 ) out->msg_qbytes = tbuf_old.msg_lqbytes;@@ -418,12 +421,13 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,struct msg_queue *msq;int err; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==MSG_SET ) {if (copy_msqid_from_user (&msqid64, buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &msg_ids (ns), msqid, cmd, + ipcp =ipcctl_pre_down (ns, &msg_ids (ns), msqid, + (cmd !=MSG_SET ) ? cmd :IPC_SET , &msqid64.msg_perm, msqid64.msg_qbytes);if (IS_ERR (ipcp))return PTR_ERR (ipcp);@@ -439,6 +443,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,freeque (ns, ipcp); goto out_up;case IPC_SET : +case MSG_SET :if (msqid64.msg_qbytes > ns->msg_ctlmnb && !capable (CAP_SYS_RESOURCE )) { err = -EPERM ;@@ -451,6 +456,9 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, msq->q_qbytes = msqid64.msg_qbytes; +if (cmd ==MSG_SET ) +ipc_update_key (&msg_ids (ns), &msqid64.msg_perm, ipcp); + msq->q_ctime =get_seconds ();/* sleeping receivers might be excluded by * stricter permissions. @@ -569,6 +577,7 @@ SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf) }case IPC_SET :case IPC_RMID : +case MSG_SET : err =msgctl_down (ns, msqid, cmd, buf, version);return err;default :security/selinux/hooks.c +1
-0@@ -4885,6 +4885,7 @@ static int selinux_msg_queue_msgctl(struct msg_queue *msq, int cmd) perms =MSGQ__GETATTR |MSGQ__ASSOCIATE ;break ;case IPC_SET : +case MSG_SET : perms =MSGQ__SETATTR ;break ;case IPC_RMID :security/smack/smack_lsm.c +1
-1@@ -2374,6 +2374,7 @@ static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd) may =MAY_READ ;break ;case IPC_SET : +case MSG_SET :case IPC_RMID : may =MAY_READWRITE ;break ; --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 6/10 glge driver: rename internal SEM_SET macro to SEM_INIT
In reply to Stanislav KinsburskyThe reason for shit patch is that SET_SET is desired to be a part of new part of API of IPC sys_semctl() system call.
The name itself for IPC is quite natural, because all linux-specific commands names for IPC system calls are originally created by replacing "IPC_" part by "SEM_"("MSG_", "SHM_") part.
So, I'm hoping, that this change doesn't really matters for "QLogic qlge NIC HBA Driver" developers, since it's just an internal define.
--- drivers/net/ethernet/qlogic/qlge/qlge.h | 4 ++-- drivers/net/ethernet/qlogic/qlge/qlge_main.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/net/ethernet/qlogic/qlge/qlge.h +2 -2
@@ -347,10 +347,10 @@ enum {enum {/* * Example: -* reg = SEM_XGMAC0_MASK | (SEM_SET << SEM_XGMAC0_SHIFT) +* reg = SEM_XGMAC0_MASK | (SEM_INIT << SEM_XGMAC0_SHIFT) */ SEM_CLEAR =0 , -SEM_SET =1 , +SEM_INIT =1 ,SEM_FORCE =3 ,SEM_XGMAC0_SHIFT =0 ,SEM_XGMAC1_SHIFT =2 ,
drivers/net/ethernet/qlogic/qlge/qlge_main.c +8 -8
@@ -109,28 +109,28 @@ static int ql_sem_trylock(struct ql_adapter *qdev, u32 sem_mask)switch (sem_mask) {case SEM_XGMAC0_MASK : - sem_bits =SEM_SET <<SEM_XGMAC0_SHIFT ; + sem_bits =SEM_INIT <<SEM_XGMAC0_SHIFT ;break ;case SEM_XGMAC1_MASK : - sem_bits =SEM_SET <<SEM_XGMAC1_SHIFT ; + sem_bits =SEM_INIT <<SEM_XGMAC1_SHIFT ;break ;case SEM_ICB_MASK : - sem_bits =SEM_SET <<SEM_ICB_SHIFT ; + sem_bits =SEM_INIT <<SEM_ICB_SHIFT ;break ;case SEM_MAC_ADDR_MASK : - sem_bits =SEM_SET <<SEM_MAC_ADDR_SHIFT ; + sem_bits =SEM_INIT <<SEM_MAC_ADDR_SHIFT ;break ;case SEM_FLASH_MASK : - sem_bits =SEM_SET <<SEM_FLASH_SHIFT ; + sem_bits =SEM_INIT <<SEM_FLASH_SHIFT ;break ;case SEM_PROBE_MASK : - sem_bits =SEM_SET <<SEM_PROBE_SHIFT ; + sem_bits =SEM_INIT <<SEM_PROBE_SHIFT ;break ;case SEM_RT_IDX_MASK : - sem_bits =SEM_SET <<SEM_RT_IDX_SHIFT ; + sem_bits =SEM_INIT <<SEM_RT_IDX_SHIFT ;break ;case SEM_PROC_REG_MASK : - sem_bits =SEM_SET <<SEM_PROC_REG_SHIFT ; + sem_bits =SEM_INIT <<SEM_PROC_REG_SHIFT ;break ;default :netif_alert (qdev, probe, qdev->ndev,"bad Semaphore mask!.\n" );
Re: [PATCH v6 06/10] glge driver: rename internal SEM_SET macro to SEM_INIT
Quoted 2 lines · Stanislav Kinsbursky
The reason for shit patch is that
SET_SETis desired to be a part of new part of API of IPCsys_semctl()system call.
[...]
Two spelling errors above. :-)
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v6 06/10] glge driver: rename internal SEM_SET macro to SEM_INIT
In reply to Stanislav KinsburskyQuoted 6 lines · Stanislav Kinsbursky
The reason for shit patch is that
SET_SETis desired to be a part of new part of API of IPCsys_semctl()system call.
The name itself for IPC is quite natural, because all linux-specific commands names for IPC system calls are originally created by replacing "IPC_" part by "SEM_"("MSG_", "SHM_") part.
So, I'm hoping, that this change doesn't really matters for "QLogic qlge NIC
Can't speak for the driver maintainer, but it does look sane.
Quoted 69 lines
HBA Driver" developers, since it's just an internal define.
--- drivers/net/ethernet/qlogic/qlge/qlge.h | 4 ++-- drivers/net/ethernet/qlogic/qlge/qlge_main.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-)drivers/net/ethernet/qlogic/qlge/qlge.h +2
-2@@ -347,10 +347,10 @@ enum {enum {/* * Example: -* reg = SEM_XGMAC0_MASK | (SEM_SET << SEM_XGMAC0_SHIFT) +* reg = SEM_XGMAC0_MASK | (SEM_INIT << SEM_XGMAC0_SHIFT) */ SEM_CLEAR =0 , -SEM_SET =1 , +SEM_INIT =1 ,SEM_FORCE =3 ,SEM_XGMAC0_SHIFT =0 ,SEM_XGMAC1_SHIFT =2 ,drivers/net/ethernet/qlogic/qlge/qlge_main.c +8
-9@@ -109,28 +109,28 @@ static int ql_sem_trylock(struct ql_adapter *qdev, u32 sem_mask)switch (sem_mask) {case SEM_XGMAC0_MASK : - sem_bits =SEM_SET <<SEM_XGMAC0_SHIFT ; + sem_bits =SEM_INIT <<SEM_XGMAC0_SHIFT ;break ;case SEM_XGMAC1_MASK : - sem_bits =SEM_SET <<SEM_XGMAC1_SHIFT ; + sem_bits =SEM_INIT <<SEM_XGMAC1_SHIFT ;break ;case SEM_ICB_MASK : - sem_bits =SEM_SET <<SEM_ICB_SHIFT ; + sem_bits =SEM_INIT <<SEM_ICB_SHIFT ;break ;case SEM_MAC_ADDR_MASK : - sem_bits =SEM_SET <<SEM_MAC_ADDR_SHIFT ; + sem_bits =SEM_INIT <<SEM_MAC_ADDR_SHIFT ;break ;case SEM_FLASH_MASK : - sem_bits =SEM_SET <<SEM_FLASH_SHIFT ; + sem_bits =SEM_INIT <<SEM_FLASH_SHIFT ;break ;case SEM_PROBE_MASK : - sem_bits =SEM_SET <<SEM_PROBE_SHIFT ; + sem_bits =SEM_INIT <<SEM_PROBE_SHIFT ;break ;case SEM_RT_IDX_MASK : - sem_bits =SEM_SET <<SEM_RT_IDX_SHIFT ; + sem_bits =SEM_INIT <<SEM_RT_IDX_SHIFT ;break ;case SEM_PROC_REG_MASK : - sem_bits =SEM_SET <<SEM_PROC_REG_SHIFT ; + sem_bits =SEM_INIT <<SEM_PROC_REG_SHIFT ;break ;default :netif_alert (qdev, probe, qdev->ndev,"bad Semaphore mask!.\n" ); --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 7/10 ipc: add new SEM_SET command for sys_semctl() call
In reply to Stanislav KinsburskyNew SEM_SET command will be interpreted exactly as IPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise -EEXIST is returned.
--- include/uapi/linux/sem.h | 1 + ipc/compat.c | 1 + ipc/sem.c | 10 ++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 12 insertions(+), 2 deletions(-)
include/uapi/linux/sem.h +1 -0
@@ -18,6 +18,7 @@/* ipcs ctl cmds */ #define SEM_STAT 18#define SEM_INFO 19 +#define SEM_SET 20/* Obsolete, used only for backwards compatibility and libc5 compiles */ struct semid_ds {
ipc/compat.c +1 -0
@@ -290,6 +290,7 @@ static long do_compat_semctl(int first, int second, int third, u32 pad)break ;case IPC_SET : +case SEM_SET :if (version ==IPC_64 ) { err =get_compat_semid64_ds (&s64,compat_ptr (pad)); }else {
ipc/sem.c +8 -2
@@ -1085,12 +1085,13 @@ static int semctl_down(struct ipc_namespace *ns, int semid,struct semid64_ds semid64;struct kern_ipc_perm *ipcp; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==SEM_SET ) {if (copy_semid_from_user (&semid64, arg.buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &sem_ids (ns), semid, cmd, + ipcp =ipcctl_pre_down (ns, &sem_ids (ns), semid, + (cmd !=SEM_SET ) ? cmd :IPC_SET , &semid64.sem_perm,0 );if (IS_ERR (ipcp))return PTR_ERR (ipcp);
@@ -1105,6 +1106,10 @@ static int semctl_down(struct ipc_namespace *ns, int semid,case IPC_RMID :freeary (ns, ipcp); goto out_up; +case SEM_SET : + err =ipc_update_key (&sem_ids (ns), &semid64.sem_perm, ipcp); +if (err) +break ;case IPC_SET : err =ipc_update_perm (&semid64.sem_perm, ipcp);if (err)
@@ -1152,6 +1157,7 @@ SYSCALL_DEFINE(semctl)(int semid, int semnum, int cmd, union semun arg)return err;case IPC_RMID :case IPC_SET : +case SEM_SET : err =semctl_down (ns, semid, cmd, version, arg);return err;default :
security/selinux/hooks.c +1 -0
@@ -5133,6 +5133,7 @@ static int selinux_sem_semctl(struct sem_array *sma, int cmd) perms =SEM__DESTROY ;break ;case IPC_SET : +case SEM_SET : perms =SEM__SETATTR ;break ;case IPC_STAT :
security/smack/smack_lsm.c +1 -0
@@ -2253,6 +2253,7 @@ static int smack_sem_semctl(struct sem_array *sma, int cmd)case SETALL :case IPC_RMID :case IPC_SET : +case SEM_SET : may =MAY_READWRITE ;break ;case IPC_INFO :
Re: [PATCH v6 07/10] ipc: add new SEM_SET command for sys_semctl() call
Quoted 6 lines · Stanislav Kinsbursky
New
SEM_SETcommand will be interpreted exactly asIPC_SET, but also will update key, cuid and cgid values. IOW, it allows to change existent key value. The fact, that key is not used is checked before update. Otherwise-EEXISTis returned.Signed-off-by Stanislav Kinsbursky <[email protected]>
(again, modulo requested /* fallthrough */ comment )
Quoted 100 lines
--- include/uapi/linux/sem.h | 1 + ipc/compat.c | 1 + ipc/sem.c | 10 ++++++++-- security/selinux/hooks.c | 1 + security/smack/smack_lsm.c | 1 + 5 files changed, 12 insertions(+), 2 deletions(-)include/uapi/linux/sem.h +1
-0@@ -18,6 +18,7 @@/* ipcs ctl cmds */ #define SEM_STAT 18#define SEM_INFO 19 +#define SEM_SET 20/* Obsolete, used only for backwards compatibility and libc5 compiles */ struct semid_ds {ipc/compat.c +1
-0@@ -290,6 +290,7 @@ static long do_compat_semctl(int first, int second, int third, u32 pad)break ;case IPC_SET : +case SEM_SET :if (version ==IPC_64 ) { err =get_compat_semid64_ds (&s64,compat_ptr (pad)); }else {ipc/sem.c +8
-2@@ -1085,12 +1085,13 @@ static int semctl_down(struct ipc_namespace *ns, int semid,struct semid64_ds semid64;struct kern_ipc_perm *ipcp; -if (cmd ==IPC_SET ) { +if (cmd ==IPC_SET || cmd ==SEM_SET ) {if (copy_semid_from_user (&semid64, arg.buf, version))return -EFAULT ; } - ipcp =ipcctl_pre_down (ns, &sem_ids (ns), semid, cmd, + ipcp =ipcctl_pre_down (ns, &sem_ids (ns), semid, + (cmd !=SEM_SET ) ? cmd :IPC_SET , &semid64.sem_perm,0 );if (IS_ERR (ipcp))return PTR_ERR (ipcp);@@ -1105,6 +1106,10 @@ static int semctl_down(struct ipc_namespace *ns, int semid,case IPC_RMID :freeary (ns, ipcp); goto out_up; +case SEM_SET : + err =ipc_update_key (&sem_ids (ns), &semid64.sem_perm, ipcp); +if (err) +break ;case IPC_SET : err =ipc_update_perm (&semid64.sem_perm, ipcp);if (err)@@ -1152,6 +1157,7 @@ SYSCALL_DEFINE(semctl)(int semid, int semnum, int cmd, union semun arg)return err;case IPC_RMID :case IPC_SET : +case SEM_SET : err =semctl_down (ns, semid, cmd, version, arg);return err;default :security/selinux/hooks.c +1
-0@@ -5133,6 +5133,7 @@ static int selinux_sem_semctl(struct sem_array *sma, int cmd) perms =SEM__DESTROY ;break ;case IPC_SET : +case SEM_SET : perms =SEM__SETATTR ;break ;case IPC_STAT :security/smack/smack_lsm.c +1
-1@@ -2253,6 +2253,7 @@ static int smack_sem_semctl(struct sem_array *sma, int cmd)case SETALL :case IPC_RMID :case IPC_SET : +case SEM_SET : may =MAY_READWRITE ;break ;case IPC_INFO : --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 8/10 IPC: message queue receive cleanup
In reply to Stanislav KinsburskyThis patch moves all message related manipulation into one function msg_fill(). Actually, two functions because of the compat one.
--- include/linux/msg.h | 5 +++-- ipc/compat.c | 36 +++++++++++++++++++----------------- ipc/msg.c | 44 +++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 40 deletions(-)
include/linux/msg.h +3 -2
@@ -34,7 +34,8 @@ struct msg_queue {/* Helper routines for sys_msgsnd and sys_msgrcv */ extern long do_msgsnd (int msqid,long mtype,void __user *mtext,size_t msgsz,int msgflg); -extern long do_msgrcv (int msqid,long *pmtype,void __user *mtext, -size_t msgsz,long msgtyp,int msgflg); +extern long do_msgrcv (int msqid,void __user *buf,size_t bufsz,long msgtyp, +int msgflg, +long (*msg_fill)(void __user *,struct msg_msg *,size_t ));#endif /* _LINUX_MSG_H */
ipc/compat.c +19 -17
@@ -341,13 +341,23 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)return do_msgsnd (first, type, up->mtext, second, third); } +long compat_do_msg_fill (void __user *dest,struct msg_msg *msg,size_t bufsz) +{ +struct compat_msgbuf __user *msgp = dest; +size_t msgsz; + +if (put_user (msg->m_type, &msgp->mtype)) +return -EFAULT ; + + msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz; +if (store_msg (msgp->mtext, msg, msgsz)) +return -EFAULT ; +return msgsz; +} +long compat_sys_msgrcv (int first,int second,int msgtyp,int third,int version,void __user *uptr) { -struct compat_msgbuf __user *up; -long type; -int err; -if (first <0 )return -EINVAL ;if (second <0 )
@@ -355,23 +365,14 @@ long compat_sys_msgrcv(int first, int second, int msgtyp, int third,if (!version) {struct compat_ipc_kludge ipck; - err = -EINVAL ;if (!uptr) - goto out; - err = -EFAULT ; +return -EINVAL ;if (copy_from_user (&ipck, uptr,sizeof (ipck))) - goto out; +return -EFAULT ; uptr =compat_ptr (ipck.msgp); msgtyp = ipck.msgtyp; } - up = uptr; - err =do_msgrcv (first, &type, up->mtext, second, msgtyp, third); -if (err <0 ) - goto out; -if (put_user (type, &up->mtype)) - err = -EFAULT ; -out: - return err; + return do_msgrcv(first, uptr, second, msgtyp, third, compat_do_msg_fill); }#else long compat_sys_semctl (int semid,int semnum,int cmd,int arg)
@@ -394,7 +395,8 @@ long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, {long err, mtype; - err =do_msgrcv (msqid, &mtype, msgp->mtext, (ssize_t )msgsz, msgtyp, msgflg); + err =do_msgrcv (msqid, &mtype, msgp->mtext, (ssize_t )msgsz, msgtyp, + msgflg, compat_do_msg_fill);if (err <0 ) goto out;
ipc/msg.c +23 -21
81 lines not on this page · raw message
Re: [PATCH v6 08/10] IPC: message queue receive cleanup
Quoted 29 lines · Stanislav Kinsbursky
This patch moves all message related manipulation into one function
msg_fill(). Actually, two functions because of the compat one.Signed-off-by Stanislav Kinsbursky <[email protected]>--- include/linux/msg.h | 5 +++-- ipc/compat.c | 36 +++++++++++++++++++----------------- ipc/msg.c | 44 +++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 40 deletions(-)include/linux/msg.h +3
-2@@ -34,7 +34,8 @@ struct msg_queue {/* Helper routines for sys_msgsnd and sys_msgrcv */ extern long do_msgsnd (int msqid,long mtype,void __user *mtext,size_t msgsz,int msgflg); -extern long do_msgrcv (int msqid,long *pmtype,void __user *mtext, -size_t msgsz,long msgtyp,int msgflg); +extern long do_msgrcv (int msqid,void __user *buf,size_t bufsz,long msgtyp, +int msgflg, +long (*msg_fill)(void __user *,struct msg_msg *,size_t ));#endif /* _LINUX_MSG_H */ ipc/compat.c +0
-0
[...]
ipc/compat.c long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, · line 402
Quoted 10 lines
ipc/compat.c +2
-1@@ -394,7 +395,8 @@ long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, {long err, mtype; - err =do_msgrcv (msqid, &mtype, msgp->mtext, (ssize_t )msgsz, msgtyp, msgflg); + err =do_msgrcv (msqid, &mtype, msgp->mtext, (ssize_t )msgsz, msgtyp, + msgflg, compat_do_msg_fill);if (err <0 ) goto out;
[...]
That isn't even the right number of arguments now...
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
PATCH v6 9/10 IPC: message queue copy feature introduced
In reply to Stanislav KinsburskyThis patch is required for checkpoint/restore in userspace.
IOW, c/r requires some way to get all pending IPC messages without deleting them from the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flag MSG_COPY for sys_msgrcv() system call was introduced. If this flag was specified, then mtype is interpreted as number of the message to copy.
If MSG_COPY is set, then kernel will allocate dummy message with passed size, and then use new copy_msg() helper function to copy desired message (instead of unlinking it from the queue).
Notes:
1) Return -ENOSYS if MSG_COPY is specified, but CONFIG_CHECKPOINT_RESTORE is not set.
--- include/uapi/linux/msg.h | 1 + ipc/msg.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-- ipc/msgutil.c | 38 +++++++++++++++++++++++++++++++++++ ipc/util.h | 1 + 4 files changed, 88 insertions(+), 2 deletions(-)
include/uapi/linux/msg.h +1 -0
@@ -11,6 +11,7 @@/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */ #define MSG_EXCEPT 020000/* recv any msg except of specified type.*/ +#define MSG_COPY 040000/* copy (not remove) all queue messages */ /* Obsolete, used only for backwards compatibility and libc5 compiles */ struct msqid_ds {
ipc/msg.c +48 -2
89 lines not on this page · raw message
ipc/msgutil.c +38 -0
@@ -100,7 +100,45 @@ out_err:free_msg (msg);return ERR_PTR (err); } +#ifdef CONFIG_CHECKPOINT_RESTORE +struct msg_msg *copy_msg (struct msg_msg *src,struct msg_msg *dst) +{ +struct msg_msgseg *dst_pseg, *src_pseg; +int len = src->m_ts; +int alen; + +BUG_ON (dst ==NULL ); +if (src->m_ts > dst->m_ts) +return ERR_PTR (-EINVAL ); + + alen = len; +if (alen >DATALEN_MSG ) + alen =DATALEN_MSG ; + + dst->next =NULL ; + dst->security =NULL ; +memcpy (dst +1 , src +1 , alen); + + len -= alen; + dst_pseg = dst->next; + src_pseg = src->next; +while (len >0 ) { + alen = len; +if (alen >DATALEN_SEG ) + alen =DATALEN_SEG ; +memcpy (dst_pseg +1 , src_pseg +1 , alen); + dst_pseg = dst_pseg->next; + len -= alen; + src_pseg = src_pseg->next; + } + + dst->m_type = src->m_type; + dst->m_ts = src->m_ts; + +return dst; +} +#endif int store_msg (void __user *dest,struct msg_msg *msg,int len) {int alen;
ipc/util.h +1 -0
@@ -142,6 +142,7 @@ int ipc_parse_version (int *cmd);extern void free_msg (struct msg_msg *msg);extern struct msg_msg *load_msg (const void __user *src,int len); +extern struct msg_msg *copy_msg (struct msg_msg *src,struct msg_msg *dst);extern int store_msg (void __user *dest,struct msg_msg *msg,int len);extern void recompute_msgmni (struct ipc_namespace *);
Re: [PATCH v6 09/10] IPC: message queue copy feature introduced
Quoted 11 lines · Stanislav Kinsbursky
This patch is required for checkpoint/restore in userspace.
IOW, c/r requires some way to get all pending IPC messages without deleting them from the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flagMSG_COPYforsys_msgrcv()system call was introduced. If this flag was specified, then mtype is interpreted as number of the message to copy.
IfMSG_COPYis set, then kernel will allocate dummy message with passed size, and then use newcopy_msg()helper function to copy desired message (instead of unlinking it from the queue).
Quoted 3 lines
Notes:
1) Return-ENOSYSifMSG_COPYis specified, butCONFIG_CHECKPOINT_RESTOREis not set.
How much could it clean things up if a new ipc/cr.c contained
#ifdef CONFIG_CHECKPOINT_RESTORE
struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst) {
...
}
#else
struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
{
return -ENOSYS;
}#endif
and you went on from there to try to remove all the new #ifdefs from the existing files?
Quoted 184 lines
Signed-off-by Stanislav Kinsbursky <[email protected]>--- include/uapi/linux/msg.h | 1 + ipc/msg.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-- ipc/msgutil.c | 38 +++++++++++++++++++++++++++++++++++ ipc/util.h | 1 + 4 files changed, 88 insertions(+), 2 deletions(-)include/uapi/linux/msg.h +1
-0@@ -11,6 +11,7 @@/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */ #define MSG_EXCEPT 020000/* recv any msg except of specified type.*/ +#define MSG_COPY 040000/* copy (not remove) all queue messages */ /* Obsolete, used only for backwards compatibility and libc5 compiles */ struct msqid_ds {ipc/msg.c +48
-2@@ -788,19 +788,48 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,struct msg_msg *msg;int mode;struct ipc_namespace *ns; +#ifdef CONFIG_CHECKPOINT_RESTORE +struct msg_msg *copy =NULL ; +unsigned long copy_number =0 ; +#endif if (msqid <0 || (long ) bufsz <0 )return -EINVAL ; +if (msgflg &MSG_COPY ) { +#ifdef CONFIG_CHECKPOINT_RESTORE + +if (msgflg &MSG_COPY ) { + copy_number = msgtyp; + msgtyp =0 ; + } + +/* +* Create dummy message to copy real message to. +*/ + copy =load_msg (buf, bufsz); +if (IS_ERR (copy)) +return PTR_ERR (copy); + copy->m_ts = bufsz; +#else +return -ENOSYS ; +#endif + } mode =convert_mode (&msgtyp, msgflg); ns = current->nsproxy->ipc_ns; msq =msg_lock_check (ns, msqid); -if (IS_ERR (msq)) +if (IS_ERR (msq)) { +#ifdef CONFIG_CHECKPOINT_RESTORE +if (msgflg &MSG_COPY ) +free_msg (copy); +#endif return PTR_ERR (msq); + }for (;;) {struct msg_receiver msr_d;struct list_head *tmp; +long msg_counter =0 ; msg =ERR_PTR (-EACCES );if (ipcperms (ns, &msq->q_perm,S_IRUGO ))@@ -820,8 +849,16 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,if (mode ==SEARCH_LESSEQUAL && walk_msg->m_type !=1 ) { msgtyp = walk_msg->m_type -1 ; +#ifdef CONFIG_CHECKPOINT_RESTORE + }else if (msgflg &MSG_COPY ) { +if (copy_number == msg_counter) { + msg =copy_msg (walk_msg, copy); +break ; + } +#endif }else break ; + msg_counter++; } tmp = tmp->next; }@@ -834,6 +871,10 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, msg =ERR_PTR (-E2BIG ); goto out_unlock; } +#ifdef CONFIG_CHECKPOINT_RESTORE +if (msgflg &MSG_COPY ) + goto out_unlock; +#endif list_del (&msg->m_list); msq->q_qnum--; msq->q_rtime =get_seconds ();@@ -917,8 +958,13 @@ out_unlock:break ; } } -if (IS_ERR (msg)) +if (IS_ERR (msg)) { +#ifdef CONFIG_CHECKPOINT_RESTORE +if (msgflg &MSG_COPY ) +free_msg (copy); +#endif return PTR_ERR (msg); + } bufsz =msg_handler (buf, msg, bufsz);free_msg (msg);ipc/msgutil.c +38
-0@@ -100,7 +100,45 @@ out_err:free_msg (msg);return ERR_PTR (err); } +#ifdef CONFIG_CHECKPOINT_RESTORE +struct msg_msg *copy_msg (struct msg_msg *src,struct msg_msg *dst) +{ +struct msg_msgseg *dst_pseg, *src_pseg; +int len = src->m_ts; +int alen; + +BUG_ON (dst ==NULL ); +if (src->m_ts > dst->m_ts) +return ERR_PTR (-EINVAL ); + + alen = len; +if (alen >DATALEN_MSG ) + alen =DATALEN_MSG ; + + dst->next =NULL ; + dst->security =NULL ; +memcpy (dst +1 , src +1 , alen); + + len -= alen; + dst_pseg = dst->next; + src_pseg = src->next; +while (len >0 ) { + alen = len; +if (alen >DATALEN_SEG ) + alen =DATALEN_SEG ; +memcpy (dst_pseg +1 , src_pseg +1 , alen); + dst_pseg = dst_pseg->next; + len -= alen; + src_pseg = src_pseg->next; + } + + dst->m_type = src->m_type; + dst->m_ts = src->m_ts; + +return dst; +} +#endif int store_msg (void __user *dest,struct msg_msg *msg,int len) {int alen;ipc/util.h +1
-1@@ -142,6 +142,7 @@ int ipc_parse_version (int *cmd);extern void free_msg (struct msg_msg *msg);extern struct msg_msg *load_msg (const void __user *src,int len); +extern struct msg_msg *copy_msg (struct msg_msg *src,struct msg_msg *dst);extern int store_msg (void __user *dest,struct msg_msg *msg,int len);extern void recompute_msgmni (struct ipc_namespace *); --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 10/10 test: IPC message queue copy feture test
In reply to Stanislav KinsburskyThis test can be used to check wheither kernel supports IPC message queue copy and restore features (required by CRIU project).
--- tools/testing/selftests/ipc/Makefile | 28 ++++ tools/testing/selftests/ipc/msgque.c | 251 ++++++++++++++++++++++++++++++++++ 2 files changed, 279 insertions(+), 0 deletions(-) create mode 100644 tools/testing/selftests/ipc/Makefile create mode 100644 tools/testing/selftests/ipc/msgque.c
tools/testing/selftests/ipc/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) +ifeq ($(ARCH),i386) + ARCH := X86 + CFLAGS := -DCONFIG_X86_32 -D__i386__ +endif +ifeq ($(ARCH),x86_64) + ARCH := X86 + CFLAGS := -DCONFIG_X86_64 -D__x86_64__ +endif + +CFLAGS += -I../../../../arch/x86/include/generated/ +CFLAGS += -I../../../../include/ +CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../arch/x86/include/ + +all: +ifeq ($(ARCH),X86) + gcc $(CFLAGS) msgque.c -o msgque_test +else + echo "Not an x86 target, can't build msgque selftest" +endif + +run_tests: all + ./msgque_test + +clean: + rm -fr ./msgque_test
tools/testing/selftests/ipc/msgque.c new file +251 -0
251 lines not on this page · raw message
Re: [PATCH v6 10/10] test: IPC message queue copy feture test
tools/testing/selftests/ipc/Makefile line 15
Quoted 4 lines · Stanislav Kinsbursky
tools/testing/selftests/ipc/Makefile new file +4
-0+CFLAGS += -I../../../../arch/x86/include/generated/ +CFLAGS += -I../../../../include/ +CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../arch/x86/include/
Do you need to add uapi/ into some of these?
David