summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/cred.h2
-rw-r--r--include/linux/lsm_hooks.h170
-rw-r--r--include/linux/sched/user.h7
-rw-r--r--kernel/seccomp.c2
-rw-r--r--security/keys/process_keys.c41
-rw-r--r--security/keys/request_key.c14
6 files changed, 115 insertions, 121 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h
index ddd45bb74887..efb6edf32de7 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -138,7 +138,7 @@ struct cred {
138#ifdef CONFIG_KEYS 138#ifdef CONFIG_KEYS
139 unsigned char jit_keyring; /* default keyring to attach requested 139 unsigned char jit_keyring; /* default keyring to attach requested
140 * keys to */ 140 * keys to */
141 struct key __rcu *session_keyring; /* keyring inherited over fork */ 141 struct key *session_keyring; /* keyring inherited over fork */
142 struct key *process_keyring; /* keyring private to this process */ 142 struct key *process_keyring; /* keyring private to this process */
143 struct key *thread_keyring; /* keyring private to this thread */ 143 struct key *thread_keyring; /* keyring private to this thread */
144 struct key *request_key_auth; /* assumed request_key authority */ 144 struct key *request_key_auth; /* assumed request_key authority */
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index a9b8ff578b6b..a240a3fc5fc4 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -127,7 +127,6 @@
127 * options cleanly (a filesystem may modify the data e.g. with strsep()). 127 * options cleanly (a filesystem may modify the data e.g. with strsep()).
128 * This also allows the original mount data to be stripped of security- 128 * This also allows the original mount data to be stripped of security-
129 * specific options to avoid having to make filesystems aware of them. 129 * specific options to avoid having to make filesystems aware of them.
130 * @type the type of filesystem being mounted.
131 * @orig the original mount data copied from userspace. 130 * @orig the original mount data copied from userspace.
132 * @copy copied data which will be passed to the security module. 131 * @copy copied data which will be passed to the security module.
133 * Returns 0 if the copy was successful. 132 * Returns 0 if the copy was successful.
@@ -320,10 +319,11 @@
320 * @new_dentry contains the dentry structure of the new link. 319 * @new_dentry contains the dentry structure of the new link.
321 * Return 0 if permission is granted. 320 * Return 0 if permission is granted.
322 * @path_chmod: 321 * @path_chmod:
323 * Check for permission to change DAC's permission of a file or directory. 322 * Check for permission to change a mode of the file @path. The new
324 * @dentry contains the dentry structure. 323 * mode is specified in @mode.
325 * @mnt contains the vfsmnt structure. 324 * @path contains the path structure of the file to change the mode.
326 * @mode contains DAC's mode. 325 * @mode contains the new DAC's permission, which is a bitmask of
326 * constants from <include/uapi/linux/stat.h>
327 * Return 0 if permission is granted. 327 * Return 0 if permission is granted.
328 * @path_chown: 328 * @path_chown:
329 * Check for permission to change owner/group of a file or directory. 329 * Check for permission to change owner/group of a file or directory.
@@ -502,7 +502,7 @@
502 * Return 0 if permission is granted. 502 * Return 0 if permission is granted.
503 * @file_lock: 503 * @file_lock:
504 * Check permission before performing file locking operations. 504 * Check permission before performing file locking operations.
505 * Note: this hook mediates both flock and fcntl style locks. 505 * Note the hook mediates both flock and fcntl style locks.
506 * @file contains the file structure. 506 * @file contains the file structure.
507 * @cmd contains the posix-translated lock operation to perform 507 * @cmd contains the posix-translated lock operation to perform
508 * (e.g. F_RDLCK, F_WRLCK). 508 * (e.g. F_RDLCK, F_WRLCK).
@@ -645,12 +645,12 @@
645 * @p contains the task_struct of process. 645 * @p contains the task_struct of process.
646 * @nice contains the new nice value. 646 * @nice contains the new nice value.
647 * Return 0 if permission is granted. 647 * Return 0 if permission is granted.
648 * @task_setioprio 648 * @task_setioprio:
649 * Check permission before setting the ioprio value of @p to @ioprio. 649 * Check permission before setting the ioprio value of @p to @ioprio.
650 * @p contains the task_struct of process. 650 * @p contains the task_struct of process.
651 * @ioprio contains the new ioprio value 651 * @ioprio contains the new ioprio value
652 * Return 0 if permission is granted. 652 * Return 0 if permission is granted.
653 * @task_getioprio 653 * @task_getioprio:
654 * Check permission before getting the ioprio value of @p. 654 * Check permission before getting the ioprio value of @p.
655 * @p contains the task_struct of process. 655 * @p contains the task_struct of process.
656 * Return 0 if permission is granted. 656 * Return 0 if permission is granted.
@@ -672,17 +672,15 @@
672 * Return 0 if permission is granted. 672 * Return 0 if permission is granted.
673 * @task_setscheduler: 673 * @task_setscheduler:
674 * Check permission before setting scheduling policy and/or parameters of 674 * Check permission before setting scheduling policy and/or parameters of
675 * process @p based on @policy and @lp. 675 * process @p.
676 * @p contains the task_struct for process. 676 * @p contains the task_struct for process.
677 * @policy contains the scheduling policy.
678 * @lp contains the scheduling parameters.
679 * Return 0 if permission is granted. 677 * Return 0 if permission is granted.
680 * @task_getscheduler: 678 * @task_getscheduler:
681 * Check permission before obtaining scheduling information for process 679 * Check permission before obtaining scheduling information for process
682 * @p. 680 * @p.
683 * @p contains the task_struct for process. 681 * @p contains the task_struct for process.
684 * Return 0 if permission is granted. 682 * Return 0 if permission is granted.
685 * @task_movememory 683 * @task_movememory:
686 * Check permission before moving memory owned by process @p. 684 * Check permission before moving memory owned by process @p.
687 * @p contains the task_struct for process. 685 * @p contains the task_struct for process.
688 * Return 0 if permission is granted. 686 * Return 0 if permission is granted.
@@ -769,9 +767,9 @@
769 * socket structure, but rather, the socket security information is stored 767 * socket structure, but rather, the socket security information is stored
770 * in the associated inode. Typically, the inode alloc_security hook will 768 * in the associated inode. Typically, the inode alloc_security hook will
771 * allocate and and attach security information to 769 * allocate and and attach security information to
772 * sock->inode->i_security. This hook may be used to update the 770 * SOCK_INODE(sock)->i_security. This hook may be used to update the
773 * sock->inode->i_security field with additional information that wasn't 771 * SOCK_INODE(sock)->i_security field with additional information that
774 * available when the inode was allocated. 772 * wasn't available when the inode was allocated.
775 * @sock contains the newly created socket structure. 773 * @sock contains the newly created socket structure.
776 * @family contains the requested protocol family. 774 * @family contains the requested protocol family.
777 * @type contains the requested communications type. 775 * @type contains the requested communications type.
@@ -876,13 +874,13 @@
876 * @socket_getpeersec_dgram: 874 * @socket_getpeersec_dgram:
877 * This hook allows the security module to provide peer socket security 875 * This hook allows the security module to provide peer socket security
878 * state for udp sockets on a per-packet basis to userspace via 876 * state for udp sockets on a per-packet basis to userspace via
879 * getsockopt SO_GETPEERSEC. The application must first have indicated 877 * getsockopt SO_GETPEERSEC. The application must first have indicated
880 * the IP_PASSSEC option via getsockopt. It can then retrieve the 878 * the IP_PASSSEC option via getsockopt. It can then retrieve the
881 * security state returned by this hook for a packet via the SCM_SECURITY 879 * security state returned by this hook for a packet via the SCM_SECURITY
882 * ancillary message type. 880 * ancillary message type.
883 * @skb is the skbuff for the packet being queried 881 * @sock contains the peer socket. May be NULL.
884 * @secdata is a pointer to a buffer in which to copy the security data 882 * @skb is the sk_buff for the packet being queried. May be NULL.
885 * @seclen is the maximum length for @secdata 883 * @secid pointer to store the secid of the packet.
886 * Return 0 on success, error on failure. 884 * Return 0 on success, error on failure.
887 * @sk_alloc_security: 885 * @sk_alloc_security:
888 * Allocate and attach a security structure to the sk->sk_security field, 886 * Allocate and attach a security structure to the sk->sk_security field,
@@ -906,9 +904,9 @@
906 * @secmark_relabel_packet: 904 * @secmark_relabel_packet:
907 * check if the process should be allowed to relabel packets to 905 * check if the process should be allowed to relabel packets to
908 * the given secid 906 * the given secid
909 * @security_secmark_refcount_inc 907 * @secmark_refcount_inc:
910 * tells the LSM to increment the number of secmark labeling rules loaded 908 * tells the LSM to increment the number of secmark labeling rules loaded
911 * @security_secmark_refcount_dec 909 * @secmark_refcount_dec:
912 * tells the LSM to decrement the number of secmark labeling rules loaded 910 * tells the LSM to decrement the number of secmark labeling rules loaded
913 * @req_classify_flow: 911 * @req_classify_flow:
914 * Sets the flow's sid to the openreq sid. 912 * Sets the flow's sid to the openreq sid.
@@ -1113,41 +1111,41 @@
1113 * 1111 *
1114 * @msg_queue_alloc_security: 1112 * @msg_queue_alloc_security:
1115 * Allocate and attach a security structure to the 1113 * Allocate and attach a security structure to the
1116 * msq->q_perm.security field. The security field is initialized to 1114 * @perm->security field. The security field is initialized to
1117 * NULL when the structure is first created. 1115 * NULL when the structure is first created.
1118 * @msq contains the message queue structure to be modified. 1116 * @perm contains the IPC permissions of the message queue.
1119 * Return 0 if operation was successful and permission is granted. 1117 * Return 0 if operation was successful and permission is granted.
1120 * @msg_queue_free_security: 1118 * @msg_queue_free_security:
1121 * Deallocate security structure for this message queue. 1119 * Deallocate security field @perm->security for the message queue.
1122 * @msq contains the message queue structure to be modified. 1120 * @perm contains the IPC permissions of the message queue.
1123 * @msg_queue_associate: 1121 * @msg_queue_associate:
1124 * Check permission when a message queue is requested through the 1122 * Check permission when a message queue is requested through the
1125 * msgget system call. This hook is only called when returning the 1123 * msgget system call. This hook is only called when returning the
1126 * message queue identifier for an existing message queue, not when a 1124 * message queue identifier for an existing message queue, not when a
1127 * new message queue is created. 1125 * new message queue is created.
1128 * @msq contains the message queue to act upon. 1126 * @perm contains the IPC permissions of the message queue.
1129 * @msqflg contains the operation control flags. 1127 * @msqflg contains the operation control flags.
1130 * Return 0 if permission is granted. 1128 * Return 0 if permission is granted.
1131 * @msg_queue_msgctl: 1129 * @msg_queue_msgctl:
1132 * Check permission when a message control operation specified by @cmd 1130 * Check permission when a message control operation specified by @cmd
1133 * is to be performed on the message queue @msq. 1131 * is to be performed on the message queue with permissions @perm.
1134 * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO. 1132 * The @perm may be NULL, e.g. for IPC_INFO or MSG_INFO.
1135 * @msq contains the message queue to act upon. May be NULL. 1133 * @perm contains the IPC permissions of the msg queue. May be NULL.
1136 * @cmd contains the operation to be performed. 1134 * @cmd contains the operation to be performed.
1137 * Return 0 if permission is granted. 1135 * Return 0 if permission is granted.
1138 * @msg_queue_msgsnd: 1136 * @msg_queue_msgsnd:
1139 * Check permission before a message, @msg, is enqueued on the message 1137 * Check permission before a message, @msg, is enqueued on the message
1140 * queue, @msq. 1138 * queue with permissions @perm.
1141 * @msq contains the message queue to send message to. 1139 * @perm contains the IPC permissions of the message queue.
1142 * @msg contains the message to be enqueued. 1140 * @msg contains the message to be enqueued.
1143 * @msqflg contains operational flags. 1141 * @msqflg contains operational flags.
1144 * Return 0 if permission is granted. 1142 * Return 0 if permission is granted.
1145 * @msg_queue_msgrcv: 1143 * @msg_queue_msgrcv:
1146 * Check permission before a message, @msg, is removed from the message 1144 * Check permission before a message, @msg, is removed from the message
1147 * queue, @msq. The @target task structure contains a pointer to the 1145 * queue. The @target task structure contains a pointer to the
1148 * process that will be receiving the message (not equal to the current 1146 * process that will be receiving the message (not equal to the current
1149 * process when inline receives are being performed). 1147 * process when inline receives are being performed).
1150 * @msq contains the message queue to retrieve message from. 1148 * @perm contains the IPC permissions of the message queue.
1151 * @msg contains the message destination. 1149 * @msg contains the message destination.
1152 * @target contains the task structure for recipient process. 1150 * @target contains the task structure for recipient process.
1153 * @type contains the type of message requested. 1151 * @type contains the type of message requested.
@@ -1157,34 +1155,34 @@
1157 * Security hooks for System V Shared Memory Segments 1155 * Security hooks for System V Shared Memory Segments
1158 * 1156 *
1159 * @shm_alloc_security: 1157 * @shm_alloc_security:
1160 * Allocate and attach a security structure to the shp->shm_perm.security 1158 * Allocate and attach a security structure to the @perm->security
1161 * field. The security field is initialized to NULL when the structure is 1159 * field. The security field is initialized to NULL when the structure is
1162 * first created. 1160 * first created.
1163 * @shp contains the shared memory structure to be modified. 1161 * @perm contains the IPC permissions of the shared memory structure.
1164 * Return 0 if operation was successful and permission is granted. 1162 * Return 0 if operation was successful and permission is granted.
1165 * @shm_free_security: 1163 * @shm_free_security:
1166 * Deallocate the security struct for this memory segment. 1164 * Deallocate the security structure @perm->security for the memory segment.
1167 * @shp contains the shared memory structure to be modified. 1165 * @perm contains the IPC permissions of the shared memory structure.
1168 * @shm_associate: 1166 * @shm_associate:
1169 * Check permission when a shared memory region is requested through the 1167 * Check permission when a shared memory region is requested through the
1170 * shmget system call. This hook is only called when returning the shared 1168 * shmget system call. This hook is only called when returning the shared
1171 * memory region identifier for an existing region, not when a new shared 1169 * memory region identifier for an existing region, not when a new shared
1172 * memory region is created. 1170 * memory region is created.
1173 * @shp contains the shared memory structure to be modified. 1171 * @perm contains the IPC permissions of the shared memory structure.
1174 * @shmflg contains the operation control flags. 1172 * @shmflg contains the operation control flags.
1175 * Return 0 if permission is granted. 1173 * Return 0 if permission is granted.
1176 * @shm_shmctl: 1174 * @shm_shmctl:
1177 * Check permission when a shared memory control operation specified by 1175 * Check permission when a shared memory control operation specified by
1178 * @cmd is to be performed on the shared memory region @shp. 1176 * @cmd is to be performed on the shared memory region with permissions @perm.
1179 * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO. 1177 * The @perm may be NULL, e.g. for IPC_INFO or SHM_INFO.
1180 * @shp contains shared memory structure to be modified. 1178 * @perm contains the IPC permissions of the shared memory structure.
1181 * @cmd contains the operation to be performed. 1179 * @cmd contains the operation to be performed.
1182 * Return 0 if permission is granted. 1180 * Return 0 if permission is granted.
1183 * @shm_shmat: 1181 * @shm_shmat:
1184 * Check permissions prior to allowing the shmat system call to attach the 1182 * Check permissions prior to allowing the shmat system call to attach the
1185 * shared memory segment @shp to the data segment of the calling process. 1183 * shared memory segment with permissions @perm to the data segment of the
1186 * The attaching address is specified by @shmaddr. 1184 * calling process. The attaching address is specified by @shmaddr.
1187 * @shp contains the shared memory structure to be modified. 1185 * @perm contains the IPC permissions of the shared memory structure.
1188 * @shmaddr contains the address to attach memory region to. 1186 * @shmaddr contains the address to attach memory region to.
1189 * @shmflg contains the operational flags. 1187 * @shmflg contains the operational flags.
1190 * Return 0 if permission is granted. 1188 * Return 0 if permission is granted.
@@ -1192,34 +1190,34 @@
1192 * Security hooks for System V Semaphores 1190 * Security hooks for System V Semaphores
1193 * 1191 *
1194 * @sem_alloc_security: 1192 * @sem_alloc_security:
1195 * Allocate and attach a security structure to the sma->sem_perm.security 1193 * Allocate and attach a security structure to the @perm->security
1196 * field. The security field is initialized to NULL when the structure is 1194 * field. The security field is initialized to NULL when the structure is
1197 * first created. 1195 * first created.
1198 * @sma contains the semaphore structure 1196 * @perm contains the IPC permissions of the semaphore.
1199 * Return 0 if operation was successful and permission is granted. 1197 * Return 0 if operation was successful and permission is granted.
1200 * @sem_free_security: 1198 * @sem_free_security:
1201 * deallocate security struct for this semaphore 1199 * Deallocate security structure @perm->security for the semaphore.
1202 * @sma contains the semaphore structure. 1200 * @perm contains the IPC permissions of the semaphore.
1203 * @sem_associate: 1201 * @sem_associate:
1204 * Check permission when a semaphore is requested through the semget 1202 * Check permission when a semaphore is requested through the semget
1205 * system call. This hook is only called when returning the semaphore 1203 * system call. This hook is only called when returning the semaphore
1206 * identifier for an existing semaphore, not when a new one must be 1204 * identifier for an existing semaphore, not when a new one must be
1207 * created. 1205 * created.
1208 * @sma contains the semaphore structure. 1206 * @perm contains the IPC permissions of the semaphore.
1209 * @semflg contains the operation control flags. 1207 * @semflg contains the operation control flags.
1210 * Return 0 if permission is granted. 1208 * Return 0 if permission is granted.
1211 * @sem_semctl: 1209 * @sem_semctl:
1212 * Check permission when a semaphore operation specified by @cmd is to be 1210 * Check permission when a semaphore operation specified by @cmd is to be
1213 * performed on the semaphore @sma. The @sma may be NULL, e.g. for 1211 * performed on the semaphore. The @perm may be NULL, e.g. for
1214 * IPC_INFO or SEM_INFO. 1212 * IPC_INFO or SEM_INFO.
1215 * @sma contains the semaphore structure. May be NULL. 1213 * @perm contains the IPC permissions of the semaphore. May be NULL.
1216 * @cmd contains the operation to be performed. 1214 * @cmd contains the operation to be performed.
1217 * Return 0 if permission is granted. 1215 * Return 0 if permission is granted.
1218 * @sem_semop: 1216 * @sem_semop:
1219 * Check permissions before performing operations on members of the 1217 * Check permissions before performing operations on members of the
1220 * semaphore set @sma. If the @alter flag is nonzero, the semaphore set 1218 * semaphore set. If the @alter flag is nonzero, the semaphore set
1221 * may be modified. 1219 * may be modified.
1222 * @sma contains the semaphore structure. 1220 * @perm contains the IPC permissions of the semaphore.
1223 * @sops contains the operations to perform. 1221 * @sops contains the operations to perform.
1224 * @nsops contains the number of operations to perform. 1222 * @nsops contains the number of operations to perform.
1225 * @alter contains the flag indicating whether changes are to be made. 1223 * @alter contains the flag indicating whether changes are to be made.
@@ -1292,13 +1290,12 @@
1292 * Check permission before accessing the kernel message ring or changing 1290 * Check permission before accessing the kernel message ring or changing
1293 * logging to the console. 1291 * logging to the console.
1294 * See the syslog(2) manual page for an explanation of the @type values. 1292 * See the syslog(2) manual page for an explanation of the @type values.
1295 * @type contains the type of action. 1293 * @type contains the SYSLOG_ACTION_* constant from <include/linux/syslog.h>
1296 * @from_file indicates the context of action (if it came from /proc).
1297 * Return 0 if permission is granted. 1294 * Return 0 if permission is granted.
1298 * @settime: 1295 * @settime:
1299 * Check permission to change the system time. 1296 * Check permission to change the system time.
1300 * struct timespec64 is defined in include/linux/time64.h and timezone 1297 * struct timespec64 is defined in <include/linux/time64.h> and timezone
1301 * is defined in include/linux/time.h 1298 * is defined in <include/linux/time.h>
1302 * @ts contains new time 1299 * @ts contains new time
1303 * @tz contains new timezone 1300 * @tz contains new timezone
1304 * Return 0 if permission is granted. 1301 * Return 0 if permission is granted.
@@ -1340,7 +1337,7 @@
1340 * @audit_rule_init: 1337 * @audit_rule_init:
1341 * Allocate and initialize an LSM audit rule structure. 1338 * Allocate and initialize an LSM audit rule structure.
1342 * @field contains the required Audit action. 1339 * @field contains the required Audit action.
1343 * Fields flags are defined in include/linux/audit.h 1340 * Fields flags are defined in <include/linux/audit.h>
1344 * @op contains the operator the rule uses. 1341 * @op contains the operator the rule uses.
1345 * @rulestr contains the context where the rule will be applied to. 1342 * @rulestr contains the context where the rule will be applied to.
1346 * @lsmrule contains a pointer to receive the result. 1343 * @lsmrule contains a pointer to receive the result.
@@ -1348,9 +1345,9 @@
1348 * -EINVAL in case of an invalid rule. 1345 * -EINVAL in case of an invalid rule.
1349 * 1346 *
1350 * @audit_rule_known: 1347 * @audit_rule_known:
1351 * Specifies whether given @rule contains any fields related to 1348 * Specifies whether given @krule contains any fields related to
1352 * current LSM. 1349 * current LSM.
1353 * @rule contains the audit rule of interest. 1350 * @krule contains the audit rule of interest.
1354 * Return 1 in case of relation found, 0 otherwise. 1351 * Return 1 in case of relation found, 0 otherwise.
1355 * 1352 *
1356 * @audit_rule_match: 1353 * @audit_rule_match:
@@ -1359,13 +1356,13 @@
1359 * @secid contains the security id in question. 1356 * @secid contains the security id in question.
1360 * @field contains the field which relates to current LSM. 1357 * @field contains the field which relates to current LSM.
1361 * @op contains the operator that will be used for matching. 1358 * @op contains the operator that will be used for matching.
1362 * @rule points to the audit rule that will be checked against. 1359 * @lrule points to the audit rule that will be checked against.
1363 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure. 1360 * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
1364 * 1361 *
1365 * @audit_rule_free: 1362 * @audit_rule_free:
1366 * Deallocate the LSM audit rule structure previously allocated by 1363 * Deallocate the LSM audit rule structure previously allocated by
1367 * audit_rule_init. 1364 * audit_rule_init.
1368 * @rule contains the allocated rule 1365 * @lsmrule contains the allocated rule
1369 * 1366 *
1370 * @inode_invalidate_secctx: 1367 * @inode_invalidate_secctx:
1371 * Notify the security module that it must revalidate the security context 1368 * Notify the security module that it must revalidate the security context
@@ -1378,9 +1375,7 @@
1378 * this hook to initialize the security context in its incore inode to the 1375 * this hook to initialize the security context in its incore inode to the
1379 * value provided by the server for the file when the server returned the 1376 * value provided by the server for the file when the server returned the
1380 * file's attributes to the client. 1377 * file's attributes to the client.
1381 *
1382 * Must be called with inode->i_mutex locked. 1378 * Must be called with inode->i_mutex locked.
1383 *
1384 * @inode we wish to set the security context of. 1379 * @inode we wish to set the security context of.
1385 * @ctx contains the string which we wish to set in the inode. 1380 * @ctx contains the string which we wish to set in the inode.
1386 * @ctxlen contains the length of @ctx. 1381 * @ctxlen contains the length of @ctx.
@@ -1393,9 +1388,7 @@
1393 * this hook to change the security context in its incore inode and on the 1388 * this hook to change the security context in its incore inode and on the
1394 * backing filesystem to a value provided by the client on a SETATTR 1389 * backing filesystem to a value provided by the client on a SETATTR
1395 * operation. 1390 * operation.
1396 *
1397 * Must be called with inode->i_mutex locked. 1391 * Must be called with inode->i_mutex locked.
1398 *
1399 * @dentry contains the inode we wish to set the security context of. 1392 * @dentry contains the inode we wish to set the security context of.
1400 * @ctx contains the string which we wish to set in the inode. 1393 * @ctx contains the string which we wish to set in the inode.
1401 * @ctxlen contains the length of @ctx. 1394 * @ctxlen contains the length of @ctx.
@@ -1403,7 +1396,6 @@
1403 * @inode_getsecctx: 1396 * @inode_getsecctx:
1404 * On success, returns 0 and fills out @ctx and @ctxlen with the security 1397 * On success, returns 0 and fills out @ctx and @ctxlen with the security
1405 * context for the given @inode. 1398 * context for the given @inode.
1406 *
1407 * @inode we wish to get the security context of. 1399 * @inode we wish to get the security context of.
1408 * @ctx is a pointer in which to place the allocated security context. 1400 * @ctx is a pointer in which to place the allocated security context.
1409 * @ctxlen points to the place to put the length of @ctx. 1401 * @ctxlen points to the place to put the length of @ctx.
@@ -1640,28 +1632,28 @@ union security_list_options {
1640 int (*msg_msg_alloc_security)(struct msg_msg *msg); 1632 int (*msg_msg_alloc_security)(struct msg_msg *msg);
1641 void (*msg_msg_free_security)(struct msg_msg *msg); 1633 void (*msg_msg_free_security)(struct msg_msg *msg);
1642 1634
1643 int (*msg_queue_alloc_security)(struct kern_ipc_perm *msq); 1635 int (*msg_queue_alloc_security)(struct kern_ipc_perm *perm);
1644 void (*msg_queue_free_security)(struct kern_ipc_perm *msq); 1636 void (*msg_queue_free_security)(struct kern_ipc_perm *perm);
1645 int (*msg_queue_associate)(struct kern_ipc_perm *msq, int msqflg); 1637 int (*msg_queue_associate)(struct kern_ipc_perm *perm, int msqflg);
1646 int (*msg_queue_msgctl)(struct kern_ipc_perm *msq, int cmd); 1638 int (*msg_queue_msgctl)(struct kern_ipc_perm *perm, int cmd);
1647 int (*msg_queue_msgsnd)(struct kern_ipc_perm *msq, struct msg_msg *msg, 1639 int (*msg_queue_msgsnd)(struct kern_ipc_perm *perm, struct msg_msg *msg,
1648 int msqflg); 1640 int msqflg);
1649 int (*msg_queue_msgrcv)(struct kern_ipc_perm *msq, struct msg_msg *msg, 1641 int (*msg_queue_msgrcv)(struct kern_ipc_perm *perm, struct msg_msg *msg,
1650 struct task_struct *target, long type, 1642 struct task_struct *target, long type,
1651 int mode); 1643 int mode);
1652 1644
1653 int (*shm_alloc_security)(struct kern_ipc_perm *shp); 1645 int (*shm_alloc_security)(struct kern_ipc_perm *perm);
1654 void (*shm_free_security)(struct kern_ipc_perm *shp); 1646 void (*shm_free_security)(struct kern_ipc_perm *perm);
1655 int (*shm_associate)(struct kern_ipc_perm *shp, int shmflg); 1647 int (*shm_associate)(struct kern_ipc_perm *perm, int shmflg);
1656 int (*shm_shmctl)(struct kern_ipc_perm *shp, int cmd); 1648 int (*shm_shmctl)(struct kern_ipc_perm *perm, int cmd);
1657 int (*shm_shmat)(struct kern_ipc_perm *shp, char __user *shmaddr, 1649 int (*shm_shmat)(struct kern_ipc_perm *perm, char __user *shmaddr,
1658 int shmflg); 1650 int shmflg);
1659 1651
1660 int (*sem_alloc_security)(struct kern_ipc_perm *sma); 1652 int (*sem_alloc_security)(struct kern_ipc_perm *perm);
1661 void (*sem_free_security)(struct kern_ipc_perm *sma); 1653 void (*sem_free_security)(struct kern_ipc_perm *perm);
1662 int (*sem_associate)(struct kern_ipc_perm *sma, int semflg); 1654 int (*sem_associate)(struct kern_ipc_perm *perm, int semflg);
1663 int (*sem_semctl)(struct kern_ipc_perm *sma, int cmd); 1655 int (*sem_semctl)(struct kern_ipc_perm *perm, int cmd);
1664 int (*sem_semop)(struct kern_ipc_perm *sma, struct sembuf *sops, 1656 int (*sem_semop)(struct kern_ipc_perm *perm, struct sembuf *sops,
1665 unsigned nsops, int alter); 1657 unsigned nsops, int alter);
1666 1658
1667 int (*netlink_send)(struct sock *sk, struct sk_buff *skb); 1659 int (*netlink_send)(struct sock *sk, struct sk_buff *skb);
diff --git a/include/linux/sched/user.h b/include/linux/sched/user.h
index c7b5f86b91a1..468d2565a9fe 100644
--- a/include/linux/sched/user.h
+++ b/include/linux/sched/user.h
@@ -31,6 +31,13 @@ struct user_struct {
31 atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */ 31 atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */
32 32
33#ifdef CONFIG_KEYS 33#ifdef CONFIG_KEYS
34 /*
35 * These pointers can only change from NULL to a non-NULL value once.
36 * Writes are protected by key_user_keyring_mutex.
37 * Unlocked readers should use READ_ONCE() unless they know that
38 * install_user_keyrings() has been called successfully (which sets
39 * these members to non-NULL values, preventing further modifications).
40 */
34 struct key *uid_keyring; /* UID specific keyring */ 41 struct key *uid_keyring; /* UID specific keyring */
35 struct key *session_keyring; /* UID's default session keyring */ 42 struct key *session_keyring; /* UID's default session keyring */
36#endif 43#endif
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 3582eeb59893..a635ecba6fe2 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -331,7 +331,7 @@ static int is_ancestor(struct seccomp_filter *parent,
331 * Expects sighand and cred_guard_mutex locks to be held. 331 * Expects sighand and cred_guard_mutex locks to be held.
332 * 332 *
333 * Returns 0 on success, -ve on error, or the pid of a thread which was 333 * Returns 0 on success, -ve on error, or the pid of a thread which was
334 * either not in the correct seccomp mode or it did not have an ancestral 334 * either not in the correct seccomp mode or did not have an ancestral
335 * seccomp filter. 335 * seccomp filter.
336 */ 336 */
337static inline pid_t seccomp_can_sync_threads(void) 337static inline pid_t seccomp_can_sync_threads(void)
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index 9320424c4a46..f05f7125a7d5 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -58,7 +58,7 @@ int install_user_keyrings(void)
58 58
59 kenter("%p{%u}", user, uid); 59 kenter("%p{%u}", user, uid);
60 60
61 if (user->uid_keyring && user->session_keyring) { 61 if (READ_ONCE(user->uid_keyring) && READ_ONCE(user->session_keyring)) {
62 kleave(" = 0 [exist]"); 62 kleave(" = 0 [exist]");
63 return 0; 63 return 0;
64 } 64 }
@@ -111,8 +111,10 @@ int install_user_keyrings(void)
111 } 111 }
112 112
113 /* install the keyrings */ 113 /* install the keyrings */
114 user->uid_keyring = uid_keyring; 114 /* paired with READ_ONCE() */
115 user->session_keyring = session_keyring; 115 smp_store_release(&user->uid_keyring, uid_keyring);
116 /* paired with READ_ONCE() */
117 smp_store_release(&user->session_keyring, session_keyring);
116 } 118 }
117 119
118 mutex_unlock(&key_user_keyring_mutex); 120 mutex_unlock(&key_user_keyring_mutex);
@@ -227,6 +229,7 @@ static int install_process_keyring(void)
227 * Install the given keyring as the session keyring of the given credentials 229 * Install the given keyring as the session keyring of the given credentials
228 * struct, replacing the existing one if any. If the given keyring is NULL, 230 * struct, replacing the existing one if any. If the given keyring is NULL,
229 * then install a new anonymous session keyring. 231 * then install a new anonymous session keyring.
232 * @cred can not be in use by any task yet.
230 * 233 *
231 * Return: 0 on success; -errno on failure. 234 * Return: 0 on success; -errno on failure.
232 */ 235 */
@@ -254,7 +257,7 @@ int install_session_keyring_to_cred(struct cred *cred, struct key *keyring)
254 257
255 /* install the keyring */ 258 /* install the keyring */
256 old = cred->session_keyring; 259 old = cred->session_keyring;
257 rcu_assign_pointer(cred->session_keyring, keyring); 260 cred->session_keyring = keyring;
258 261
259 if (old) 262 if (old)
260 key_put(old); 263 key_put(old);
@@ -339,6 +342,7 @@ void key_fsgid_changed(struct task_struct *tsk)
339key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx) 342key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx)
340{ 343{
341 key_ref_t key_ref, ret, err; 344 key_ref_t key_ref, ret, err;
345 const struct cred *cred = ctx->cred;
342 346
343 /* we want to return -EAGAIN or -ENOKEY if any of the keyrings were 347 /* we want to return -EAGAIN or -ENOKEY if any of the keyrings were
344 * searchable, but we failed to find a key or we found a negative key; 348 * searchable, but we failed to find a key or we found a negative key;
@@ -352,9 +356,9 @@ key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx)
352 err = ERR_PTR(-EAGAIN); 356 err = ERR_PTR(-EAGAIN);
353 357
354 /* search the thread keyring first */ 358 /* search the thread keyring first */
355 if (ctx->cred->thread_keyring) { 359 if (cred->thread_keyring) {
356 key_ref = keyring_search_aux( 360 key_ref = keyring_search_aux(
357 make_key_ref(ctx->cred->thread_keyring, 1), ctx); 361 make_key_ref(cred->thread_keyring, 1), ctx);
358 if (!IS_ERR(key_ref)) 362 if (!IS_ERR(key_ref))
359 goto found; 363 goto found;
360 364
@@ -370,9 +374,9 @@ key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx)
370 } 374 }
371 375
372 /* search the process keyring second */ 376 /* search the process keyring second */
373 if (ctx->cred->process_keyring) { 377 if (cred->process_keyring) {
374 key_ref = keyring_search_aux( 378 key_ref = keyring_search_aux(
375 make_key_ref(ctx->cred->process_keyring, 1), ctx); 379 make_key_ref(cred->process_keyring, 1), ctx);
376 if (!IS_ERR(key_ref)) 380 if (!IS_ERR(key_ref))
377 goto found; 381 goto found;
378 382
@@ -391,12 +395,9 @@ key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx)
391 } 395 }
392 396
393 /* search the session keyring */ 397 /* search the session keyring */
394 if (ctx->cred->session_keyring) { 398 if (cred->session_keyring) {
395 rcu_read_lock();
396 key_ref = keyring_search_aux( 399 key_ref = keyring_search_aux(
397 make_key_ref(rcu_dereference(ctx->cred->session_keyring), 1), 400 make_key_ref(cred->session_keyring, 1), ctx);
398 ctx);
399 rcu_read_unlock();
400 401
401 if (!IS_ERR(key_ref)) 402 if (!IS_ERR(key_ref))
402 goto found; 403 goto found;
@@ -415,9 +416,9 @@ key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx)
415 } 416 }
416 } 417 }
417 /* or search the user-session keyring */ 418 /* or search the user-session keyring */
418 else if (ctx->cred->user->session_keyring) { 419 else if (READ_ONCE(cred->user->session_keyring)) {
419 key_ref = keyring_search_aux( 420 key_ref = keyring_search_aux(
420 make_key_ref(ctx->cred->user->session_keyring, 1), 421 make_key_ref(READ_ONCE(cred->user->session_keyring), 1),
421 ctx); 422 ctx);
422 if (!IS_ERR(key_ref)) 423 if (!IS_ERR(key_ref))
423 goto found; 424 goto found;
@@ -604,7 +605,7 @@ try_again:
604 goto error; 605 goto error;
605 goto reget_creds; 606 goto reget_creds;
606 } else if (ctx.cred->session_keyring == 607 } else if (ctx.cred->session_keyring ==
607 ctx.cred->user->session_keyring && 608 READ_ONCE(ctx.cred->user->session_keyring) &&
608 lflags & KEY_LOOKUP_CREATE) { 609 lflags & KEY_LOOKUP_CREATE) {
609 ret = join_session_keyring(NULL); 610 ret = join_session_keyring(NULL);
610 if (ret < 0) 611 if (ret < 0)
@@ -612,15 +613,13 @@ try_again:
612 goto reget_creds; 613 goto reget_creds;
613 } 614 }
614 615
615 rcu_read_lock(); 616 key = ctx.cred->session_keyring;
616 key = rcu_dereference(ctx.cred->session_keyring);
617 __key_get(key); 617 __key_get(key);
618 rcu_read_unlock();
619 key_ref = make_key_ref(key, 1); 618 key_ref = make_key_ref(key, 1);
620 break; 619 break;
621 620
622 case KEY_SPEC_USER_KEYRING: 621 case KEY_SPEC_USER_KEYRING:
623 if (!ctx.cred->user->uid_keyring) { 622 if (!READ_ONCE(ctx.cred->user->uid_keyring)) {
624 ret = install_user_keyrings(); 623 ret = install_user_keyrings();
625 if (ret < 0) 624 if (ret < 0)
626 goto error; 625 goto error;
@@ -632,7 +631,7 @@ try_again:
632 break; 631 break;
633 632
634 case KEY_SPEC_USER_SESSION_KEYRING: 633 case KEY_SPEC_USER_SESSION_KEYRING:
635 if (!ctx.cred->user->session_keyring) { 634 if (!READ_ONCE(ctx.cred->user->session_keyring)) {
636 ret = install_user_keyrings(); 635 ret = install_user_keyrings();
637 if (ret < 0) 636 if (ret < 0)
638 goto error; 637 goto error;
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index 2f17d84d46f1..75d87f9e0f49 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -142,12 +142,10 @@ static int call_sbin_request_key(struct key *authkey, void *aux)
142 prkey = cred->process_keyring->serial; 142 prkey = cred->process_keyring->serial;
143 sprintf(keyring_str[1], "%d", prkey); 143 sprintf(keyring_str[1], "%d", prkey);
144 144
145 rcu_read_lock(); 145 session = cred->session_keyring;
146 session = rcu_dereference(cred->session_keyring);
147 if (!session) 146 if (!session)
148 session = cred->user->session_keyring; 147 session = cred->user->session_keyring;
149 sskey = session->serial; 148 sskey = session->serial;
150 rcu_read_unlock();
151 149
152 sprintf(keyring_str[2], "%d", sskey); 150 sprintf(keyring_str[2], "%d", sskey);
153 151
@@ -287,10 +285,7 @@ static int construct_get_dest_keyring(struct key **_dest_keyring)
287 285
288 /* fall through */ 286 /* fall through */
289 case KEY_REQKEY_DEFL_SESSION_KEYRING: 287 case KEY_REQKEY_DEFL_SESSION_KEYRING:
290 rcu_read_lock(); 288 dest_keyring = key_get(cred->session_keyring);
291 dest_keyring = key_get(
292 rcu_dereference(cred->session_keyring));
293 rcu_read_unlock();
294 289
295 if (dest_keyring) 290 if (dest_keyring)
296 break; 291 break;
@@ -298,11 +293,12 @@ static int construct_get_dest_keyring(struct key **_dest_keyring)
298 /* fall through */ 293 /* fall through */
299 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING: 294 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
300 dest_keyring = 295 dest_keyring =
301 key_get(cred->user->session_keyring); 296 key_get(READ_ONCE(cred->user->session_keyring));
302 break; 297 break;
303 298
304 case KEY_REQKEY_DEFL_USER_KEYRING: 299 case KEY_REQKEY_DEFL_USER_KEYRING:
305 dest_keyring = key_get(cred->user->uid_keyring); 300 dest_keyring =
301 key_get(READ_ONCE(cred->user->uid_keyring));
306 break; 302 break;
307 303
308 case KEY_REQKEY_DEFL_GROUP_KEYRING: 304 case KEY_REQKEY_DEFL_GROUP_KEYRING: