Skip to content

Commit 17dec0a

Browse files
committed
Merge branch 'userns-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull namespace updates from Eric Biederman: "There was a lot of work this cycle fixing bugs that were discovered after the merge window and getting everything ready where we can reasonably support fully unprivileged fuse. The bug fixes you already have and much of the unprivileged fuse work is coming in via other trees. Still left for fully unprivileged fuse is figuring out how to cleanly handle .set_acl and .get_acl in the legacy case, and properly handling of evm xattrs on unprivileged mounts. Included in the tree is a cleanup from Alexely that replaced a linked list with a statically allocated fix sized array for the pid caches, which simplifies and speeds things up. Then there is are some cleanups and fixes for the ipc namespace. The motivation was that in reviewing other code it was discovered that access ipc objects from different pid namespaces recorded pids in such a way that when asked the wrong pids were returned. In the worst case there has been a measured 30% performance impact for sysvipc semaphores. Other test cases showed no measurable performance impact. Manfred Spraul and Davidlohr Bueso who tend to work on sysvipc performance both gave the nod that this is good enough. Casey Schaufler and James Morris have given their approval to the LSM side of the changes. I simplified the types and the code dealing with sysvipc to pass just kern_ipc_perm for all three types of ipc. Which reduced the header dependencies throughout the kernel and simplified the lsm code. Which let me work on the pid fixes without having to worry about trivial changes causing complete kernel recompiles" * 'userns-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: ipc/shm: Fix pid freeing. ipc/shm: fix up for struct file no longer being available in shm.h ipc/smack: Tidy up from the change in type of the ipc security hooks ipc: Directly call the security hook in ipc_ops.associate ipc/sem: Fix semctl(..., GETPID, ...) between pid namespaces ipc/msg: Fix msgctl(..., IPC_STAT, ...) between pid namespaces ipc/shm: Fix shmctl(..., IPC_STAT, ...) between pid namespaces. ipc/util: Helpers for making the sysvipc operations pid namespace aware ipc: Move IPCMNI from include/ipc.h into ipc/util.h msg: Move struct msg_queue into ipc/msg.c shm: Move struct shmid_kernel into ipc/shm.c sem: Move struct sem and struct sem_array into ipc/sem.c msg/security: Pass kern_ipc_perm not msg_queue into the msg_queue security hooks shm/security: Pass kern_ipc_perm not shmid_kernel into the shm security hooks sem/security: Pass kern_ipc_perm not sem_array into the sem security hooks pidns: simpler allocation of pid_* caches
2 parents d92cd81 + 2236d4d commit 17dec0a

File tree

15 files changed

+346
-455
lines changed

15 files changed

+346
-455
lines changed

include/linux/ipc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <uapi/linux/ipc.h>
99
#include <linux/refcount.h>
1010

11-
#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
12-
1311
/* used by in-kernel data structures */
1412
struct kern_ipc_perm {
1513
spinlock_t lock;

include/linux/lsm_hooks.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,28 +1575,28 @@ union security_list_options {
15751575
int (*msg_msg_alloc_security)(struct msg_msg *msg);
15761576
void (*msg_msg_free_security)(struct msg_msg *msg);
15771577

1578-
int (*msg_queue_alloc_security)(struct msg_queue *msq);
1579-
void (*msg_queue_free_security)(struct msg_queue *msq);
1580-
int (*msg_queue_associate)(struct msg_queue *msq, int msqflg);
1581-
int (*msg_queue_msgctl)(struct msg_queue *msq, int cmd);
1582-
int (*msg_queue_msgsnd)(struct msg_queue *msq, struct msg_msg *msg,
1578+
int (*msg_queue_alloc_security)(struct kern_ipc_perm *msq);
1579+
void (*msg_queue_free_security)(struct kern_ipc_perm *msq);
1580+
int (*msg_queue_associate)(struct kern_ipc_perm *msq, int msqflg);
1581+
int (*msg_queue_msgctl)(struct kern_ipc_perm *msq, int cmd);
1582+
int (*msg_queue_msgsnd)(struct kern_ipc_perm *msq, struct msg_msg *msg,
15831583
int msqflg);
1584-
int (*msg_queue_msgrcv)(struct msg_queue *msq, struct msg_msg *msg,
1584+
int (*msg_queue_msgrcv)(struct kern_ipc_perm *msq, struct msg_msg *msg,
15851585
struct task_struct *target, long type,
15861586
int mode);
15871587

1588-
int (*shm_alloc_security)(struct shmid_kernel *shp);
1589-
void (*shm_free_security)(struct shmid_kernel *shp);
1590-
int (*shm_associate)(struct shmid_kernel *shp, int shmflg);
1591-
int (*shm_shmctl)(struct shmid_kernel *shp, int cmd);
1592-
int (*shm_shmat)(struct shmid_kernel *shp, char __user *shmaddr,
1588+
int (*shm_alloc_security)(struct kern_ipc_perm *shp);
1589+
void (*shm_free_security)(struct kern_ipc_perm *shp);
1590+
int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg);
1591+
int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd);
1592+
int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr,
15931593
int shmflg);
15941594

1595-
int (*sem_alloc_security)(struct sem_array *sma);
1596-
void (*sem_free_security)(struct sem_array *sma);
1597-
int (*sem_associate)(struct sem_array *sma, int semflg);
1598-
int (*sem_semctl)(struct sem_array *sma, int cmd);
1599-
int (*sem_semop)(struct sem_array *sma, struct sembuf *sops,
1595+
int (*sem_alloc_security)(struct kern_ipc_perm *sma);
1596+
void (*sem_free_security)(struct kern_ipc_perm *sma);
1597+
int (*sem_associate)(struct kern_ipc_perm *sma, int semflg);
1598+
int (*sem_semctl)(struct kern_ipc_perm *sma, int cmd);
1599+
int (*sem_semop)(struct kern_ipc_perm *sma, struct sembuf *sops,
16001600
unsigned nsops, int alter);
16011601

16021602
int (*netlink_send)(struct sock *sk, struct sk_buff *skb);

include/linux/msg.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#define _LINUX_MSG_H
44

55
#include <linux/list.h>
6-
#include <linux/time64.h>
76
#include <uapi/linux/msg.h>
87

98
/* one msg_msg structure for each message */
@@ -16,21 +15,4 @@ struct msg_msg {
1615
/* the actual message follows immediately */
1716
};
1817

19-
/* one msq_queue structure for each present queue on the system */
20-
struct msg_queue {
21-
struct kern_ipc_perm q_perm;
22-
time64_t q_stime; /* last msgsnd time */
23-
time64_t q_rtime; /* last msgrcv time */
24-
time64_t q_ctime; /* last change time */
25-
unsigned long q_cbytes; /* current number of bytes on queue */
26-
unsigned long q_qnum; /* number of messages in queue */
27-
unsigned long q_qbytes; /* max number of bytes on queue */
28-
pid_t q_lspid; /* pid of last msgsnd */
29-
pid_t q_lrpid; /* last receive pid */
30-
31-
struct list_head q_messages;
32-
struct list_head q_receivers;
33-
struct list_head q_senders;
34-
} __randomize_layout;
35-
3618
#endif /* _LINUX_MSG_H */

include/linux/security.h

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct linux_binprm;
3636
struct cred;
3737
struct rlimit;
3838
struct siginfo;
39-
struct sem_array;
4039
struct sembuf;
4140
struct kern_ipc_perm;
4241
struct audit_context;
@@ -50,9 +49,7 @@ struct qstr;
5049
struct iattr;
5150
struct fown_struct;
5251
struct file_operations;
53-
struct shmid_kernel;
5452
struct msg_msg;
55-
struct msg_queue;
5653
struct xattr;
5754
struct xfrm_sec_ctx;
5855
struct mm_struct;
@@ -355,24 +352,24 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
355352
void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
356353
int security_msg_msg_alloc(struct msg_msg *msg);
357354
void security_msg_msg_free(struct msg_msg *msg);
358-
int security_msg_queue_alloc(struct msg_queue *msq);
359-
void security_msg_queue_free(struct msg_queue *msq);
360-
int security_msg_queue_associate(struct msg_queue *msq, int msqflg);
361-
int security_msg_queue_msgctl(struct msg_queue *msq, int cmd);
362-
int security_msg_queue_msgsnd(struct msg_queue *msq,
355+
int security_msg_queue_alloc(struct kern_ipc_perm *msq);
356+
void security_msg_queue_free(struct kern_ipc_perm *msq);
357+
int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg);
358+
int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd);
359+
int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
363360
struct msg_msg *msg, int msqflg);
364-
int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
361+
int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg,
365362
struct task_struct *target, long type, int mode);
366-
int security_shm_alloc(struct shmid_kernel *shp);
367-
void security_shm_free(struct shmid_kernel *shp);
368-
int security_shm_associate(struct shmid_kernel *shp, int shmflg);
369-
int security_shm_shmctl(struct shmid_kernel *shp, int cmd);
370-
int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg);
371-
int security_sem_alloc(struct sem_array *sma);
372-
void security_sem_free(struct sem_array *sma);
373-
int security_sem_associate(struct sem_array *sma, int semflg);
374-
int security_sem_semctl(struct sem_array *sma, int cmd);
375-
int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
363+
int security_shm_alloc(struct kern_ipc_perm *shp);
364+
void security_shm_free(struct kern_ipc_perm *shp);
365+
int security_shm_associate(struct kern_ipc_perm *shp, int shmflg);
366+
int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd);
367+
int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg);
368+
int security_sem_alloc(struct kern_ipc_perm *sma);
369+
void security_sem_free(struct kern_ipc_perm *sma);
370+
int security_sem_associate(struct kern_ipc_perm *sma, int semflg);
371+
int security_sem_semctl(struct kern_ipc_perm *sma, int cmd);
372+
int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops,
376373
unsigned nsops, int alter);
377374
void security_d_instantiate(struct dentry *dentry, struct inode *inode);
378375
int security_getprocattr(struct task_struct *p, char *name, char **value);
@@ -1045,83 +1042,83 @@ static inline int security_msg_msg_alloc(struct msg_msg *msg)
10451042
static inline void security_msg_msg_free(struct msg_msg *msg)
10461043
{ }
10471044

1048-
static inline int security_msg_queue_alloc(struct msg_queue *msq)
1045+
static inline int security_msg_queue_alloc(struct kern_ipc_perm *msq)
10491046
{
10501047
return 0;
10511048
}
10521049

1053-
static inline void security_msg_queue_free(struct msg_queue *msq)
1050+
static inline void security_msg_queue_free(struct kern_ipc_perm *msq)
10541051
{ }
10551052

1056-
static inline int security_msg_queue_associate(struct msg_queue *msq,
1053+
static inline int security_msg_queue_associate(struct kern_ipc_perm *msq,
10571054
int msqflg)
10581055
{
10591056
return 0;
10601057
}
10611058

1062-
static inline int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1059+
static inline int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
10631060
{
10641061
return 0;
10651062
}
10661063

1067-
static inline int security_msg_queue_msgsnd(struct msg_queue *msq,
1064+
static inline int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
10681065
struct msg_msg *msg, int msqflg)
10691066
{
10701067
return 0;
10711068
}
10721069

1073-
static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
1070+
static inline int security_msg_queue_msgrcv(struct kern_ipc_perm *msq,
10741071
struct msg_msg *msg,
10751072
struct task_struct *target,
10761073
long type, int mode)
10771074
{
10781075
return 0;
10791076
}
10801077

1081-
static inline int security_shm_alloc(struct shmid_kernel *shp)
1078+
static inline int security_shm_alloc(struct kern_ipc_perm *shp)
10821079
{
10831080
return 0;
10841081
}
10851082

1086-
static inline void security_shm_free(struct shmid_kernel *shp)
1083+
static inline void security_shm_free(struct kern_ipc_perm *shp)
10871084
{ }
10881085

1089-
static inline int security_shm_associate(struct shmid_kernel *shp,
1086+
static inline int security_shm_associate(struct kern_ipc_perm *shp,
10901087
int shmflg)
10911088
{
10921089
return 0;
10931090
}
10941091

1095-
static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1092+
static inline int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
10961093
{
10971094
return 0;
10981095
}
10991096

1100-
static inline int security_shm_shmat(struct shmid_kernel *shp,
1097+
static inline int security_shm_shmat(struct kern_ipc_perm *shp,
11011098
char __user *shmaddr, int shmflg)
11021099
{
11031100
return 0;
11041101
}
11051102

1106-
static inline int security_sem_alloc(struct sem_array *sma)
1103+
static inline int security_sem_alloc(struct kern_ipc_perm *sma)
11071104
{
11081105
return 0;
11091106
}
11101107

1111-
static inline void security_sem_free(struct sem_array *sma)
1108+
static inline void security_sem_free(struct kern_ipc_perm *sma)
11121109
{ }
11131110

1114-
static inline int security_sem_associate(struct sem_array *sma, int semflg)
1111+
static inline int security_sem_associate(struct kern_ipc_perm *sma, int semflg)
11151112
{
11161113
return 0;
11171114
}
11181115

1119-
static inline int security_sem_semctl(struct sem_array *sma, int cmd)
1116+
static inline int security_sem_semctl(struct kern_ipc_perm *sma, int cmd)
11201117
{
11211118
return 0;
11221119
}
11231120

1124-
static inline int security_sem_semop(struct sem_array *sma,
1121+
static inline int security_sem_semop(struct kern_ipc_perm *sma,
11251122
struct sembuf *sops, unsigned nsops,
11261123
int alter)
11271124
{

include/linux/sem.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,10 @@
22
#ifndef _LINUX_SEM_H
33
#define _LINUX_SEM_H
44

5-
#include <linux/atomic.h>
6-
#include <linux/rcupdate.h>
7-
#include <linux/cache.h>
8-
#include <linux/time64.h>
95
#include <uapi/linux/sem.h>
106

117
struct task_struct;
12-
13-
/* One semaphore structure for each semaphore in the system. */
14-
struct sem {
15-
int semval; /* current value */
16-
/*
17-
* PID of the process that last modified the semaphore. For
18-
* Linux, specifically these are:
19-
* - semop
20-
* - semctl, via SETVAL and SETALL.
21-
* - at task exit when performing undo adjustments (see exit_sem).
22-
*/
23-
int sempid;
24-
spinlock_t lock; /* spinlock for fine-grained semtimedop */
25-
struct list_head pending_alter; /* pending single-sop operations */
26-
/* that alter the semaphore */
27-
struct list_head pending_const; /* pending single-sop operations */
28-
/* that do not alter the semaphore*/
29-
time_t sem_otime; /* candidate for sem_otime */
30-
} ____cacheline_aligned_in_smp;
31-
32-
/* One sem_array data structure for each set of semaphores in the system. */
33-
struct sem_array {
34-
struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
35-
time64_t sem_ctime; /* create/last semctl() time */
36-
struct list_head pending_alter; /* pending operations */
37-
/* that alter the array */
38-
struct list_head pending_const; /* pending complex operations */
39-
/* that do not alter semvals */
40-
struct list_head list_id; /* undo requests on this array */
41-
int sem_nsems; /* no. of semaphores in array */
42-
int complex_count; /* pending complex operations */
43-
unsigned int use_global_lock;/* >0: global lock required */
44-
45-
struct sem sems[];
46-
} __randomize_layout;
8+
struct sem_undo_list;
479

4810
#ifdef CONFIG_SYSVIPC
4911

include/linux/shm.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@
77
#include <uapi/linux/shm.h>
88
#include <asm/shmparam.h>
99

10-
struct shmid_kernel /* private to the kernel */
11-
{
12-
struct kern_ipc_perm shm_perm;
13-
struct file *shm_file;
14-
unsigned long shm_nattch;
15-
unsigned long shm_segsz;
16-
time64_t shm_atim;
17-
time64_t shm_dtim;
18-
time64_t shm_ctim;
19-
pid_t shm_cprid;
20-
pid_t shm_lprid;
21-
struct user_struct *mlock_user;
22-
23-
/* The task created the shm object. NULL if the task is dead. */
24-
struct task_struct *shm_creator;
25-
struct list_head shm_clist; /* list by creator */
26-
} __randomize_layout;
27-
28-
/* shm_mode upper byte flags */
29-
#define SHM_DEST 01000 /* segment will be destroyed on last detach */
30-
#define SHM_LOCKED 02000 /* segment will not be swapped */
10+
struct file;
3111

3212
#ifdef CONFIG_SYSVIPC
3313
struct sysv_shm {

0 commit comments

Comments
 (0)