Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Work around lockdep limitation in sockets that use sockets

Lockdep issues a circular dependency warning when AFS issues an operation
through AF_RXRPC from a context in which the VFS/VM holds the mmap_sem.

The theory lockdep comes up with is as follows:

(1) If the pagefault handler decides it needs to read pages from AFS, it
calls AFS with mmap_sem held and AFS begins an AF_RXRPC call, but
creating a call requires the socket lock:

mmap_sem must be taken before sk_lock-AF_RXRPC

(2) afs_open_socket() opens an AF_RXRPC socket and binds it. rxrpc_bind()
binds the underlying UDP socket whilst holding its socket lock.
inet_bind() takes its own socket lock:

sk_lock-AF_RXRPC must be taken before sk_lock-AF_INET

(3) Reading from a TCP socket into a userspace buffer might cause a fault
and thus cause the kernel to take the mmap_sem, but the TCP socket is
locked whilst doing this:

sk_lock-AF_INET must be taken before mmap_sem

However, lockdep's theory is wrong in this instance because it deals only
with lock classes and not individual locks. The AF_INET lock in (2) isn't
really equivalent to the AF_INET lock in (3) as the former deals with a
socket entirely internal to the kernel that never sees userspace. This is
a limitation in the design of lockdep.

Fix the general case by:

(1) Double up all the locking keys used in sockets so that one set are
used if the socket is created by userspace and the other set is used
if the socket is created by the kernel.

(2) Store the kern parameter passed to sk_alloc() in a variable in the
sock struct (sk_kern_sock). This informs sock_lock_init(),
sock_init_data() and sk_clone_lock() as to the lock keys to be used.

Note that the child created by sk_clone_lock() inherits the parent's
kern setting.

(3) Add a 'kern' parameter to ->accept() that is analogous to the one
passed in to ->create() that distinguishes whether kernel_accept() or
sys_accept4() was the caller and can be passed to sk_alloc().

Note that a lot of accept functions merely dequeue an already
allocated socket. I haven't touched these as the new socket already
exists before we get the parameter.

Note also that there are a couple of places where I've made the accepted
socket unconditionally kernel-based:

irda_accept()
rds_rcp_accept_one()
tcp_accept_from_sock()

because they follow a sock_create_kern() and accept off of that.

Whilst creating this, I noticed that lustre and ocfs don't create sockets
through sock_create_kern() and thus they aren't marked as for-kernel,
though they appear to be internal. I wonder if these should do that so
that they use the new set of lock keys.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David Howells and committed by
David S. Miller
cdfbabfb 81dca07b

+142 -108
+5 -4
crypto/af_alg.c
··· 266 266 return err; 267 267 } 268 268 269 - int af_alg_accept(struct sock *sk, struct socket *newsock) 269 + int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern) 270 270 { 271 271 struct alg_sock *ask = alg_sk(sk); 272 272 const struct af_alg_type *type; ··· 281 281 if (!type) 282 282 goto unlock; 283 283 284 - sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, 0); 284 + sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, kern); 285 285 err = -ENOMEM; 286 286 if (!sk2) 287 287 goto unlock; ··· 323 323 } 324 324 EXPORT_SYMBOL_GPL(af_alg_accept); 325 325 326 - static int alg_accept(struct socket *sock, struct socket *newsock, int flags) 326 + static int alg_accept(struct socket *sock, struct socket *newsock, int flags, 327 + bool kern) 327 328 { 328 - return af_alg_accept(sock->sk, newsock); 329 + return af_alg_accept(sock->sk, newsock, kern); 329 330 } 330 331 331 332 static const struct proto_ops alg_proto_ops = {
+5 -4
crypto/algif_hash.c
··· 239 239 return err ?: len; 240 240 } 241 241 242 - static int hash_accept(struct socket *sock, struct socket *newsock, int flags) 242 + static int hash_accept(struct socket *sock, struct socket *newsock, int flags, 243 + bool kern) 243 244 { 244 245 struct sock *sk = sock->sk; 245 246 struct alg_sock *ask = alg_sk(sk); ··· 261 260 if (err) 262 261 return err; 263 262 264 - err = af_alg_accept(ask->parent, newsock); 263 + err = af_alg_accept(ask->parent, newsock, kern); 265 264 if (err) 266 265 return err; 267 266 ··· 379 378 } 380 379 381 380 static int hash_accept_nokey(struct socket *sock, struct socket *newsock, 382 - int flags) 381 + int flags, bool kern) 383 382 { 384 383 int err; 385 384 ··· 387 386 if (err) 388 387 return err; 389 388 390 - return hash_accept(sock, newsock, flags); 389 + return hash_accept(sock, newsock, flags, kern); 391 390 } 392 391 393 392 static struct proto_ops algif_hash_ops_nokey = {
+2 -2
drivers/staging/lustre/lnet/lnet/lib-socket.c
··· 532 532 533 533 newsock->ops = sock->ops; 534 534 535 - rc = sock->ops->accept(sock, newsock, O_NONBLOCK); 535 + rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false); 536 536 if (rc == -EAGAIN) { 537 537 /* Nothing ready, so wait for activity */ 538 538 init_waitqueue_entry(&wait, current); ··· 540 540 set_current_state(TASK_INTERRUPTIBLE); 541 541 schedule(); 542 542 remove_wait_queue(sk_sleep(sock->sk), &wait); 543 - rc = sock->ops->accept(sock, newsock, O_NONBLOCK); 543 + rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false); 544 544 } 545 545 546 546 if (rc)
+1 -1
fs/dlm/lowcomms.c
··· 743 743 newsock->type = con->sock->type; 744 744 newsock->ops = con->sock->ops; 745 745 746 - result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK); 746 + result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK, true); 747 747 if (result < 0) 748 748 goto accept_err; 749 749
+1 -1
fs/ocfs2/cluster/tcp.c
··· 1863 1863 1864 1864 new_sock->type = sock->type; 1865 1865 new_sock->ops = sock->ops; 1866 - ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); 1866 + ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, false); 1867 1867 if (ret < 0) 1868 1868 goto out; 1869 1869
+1 -1
include/crypto/if_alg.h
··· 73 73 74 74 int af_alg_release(struct socket *sock); 75 75 void af_alg_release_parent(struct sock *sk); 76 - int af_alg_accept(struct sock *sk, struct socket *newsock); 76 + int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern); 77 77 78 78 int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); 79 79 void af_alg_free_sg(struct af_alg_sgl *sgl);
+1 -1
include/linux/net.h
··· 146 146 int (*socketpair)(struct socket *sock1, 147 147 struct socket *sock2); 148 148 int (*accept) (struct socket *sock, 149 - struct socket *newsock, int flags); 149 + struct socket *newsock, int flags, bool kern); 150 150 int (*getname) (struct socket *sock, 151 151 struct sockaddr *addr, 152 152 int *sockaddr_len, int peer);
+2 -1
include/net/inet_common.h
··· 20 20 int addr_len, int flags, int is_sendmsg); 21 21 int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr, 22 22 int addr_len, int flags); 23 - int inet_accept(struct socket *sock, struct socket *newsock, int flags); 23 + int inet_accept(struct socket *sock, struct socket *newsock, int flags, 24 + bool kern); 24 25 int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size); 25 26 ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset, 26 27 size_t size, int flags);
+1 -1
include/net/inet_connection_sock.h
··· 258 258 return (unsigned long)min_t(u64, when, max_when); 259 259 } 260 260 261 - struct sock *inet_csk_accept(struct sock *sk, int flags, int *err); 261 + struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern); 262 262 263 263 int inet_csk_get_port(struct sock *sk, unsigned short snum); 264 264
+2 -1
include/net/sctp/structs.h
··· 476 476 int (*send_verify) (struct sctp_sock *, union sctp_addr *); 477 477 int (*supported_addrs)(const struct sctp_sock *, __be16 *); 478 478 struct sock *(*create_accept_sk) (struct sock *sk, 479 - struct sctp_association *asoc); 479 + struct sctp_association *asoc, 480 + bool kern); 480 481 int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr); 481 482 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk); 482 483 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
+6 -3
include/net/sock.h
··· 236 236 * @sk_shutdown: mask of %SEND_SHUTDOWN and/or %RCV_SHUTDOWN 237 237 * @sk_userlocks: %SO_SNDBUF and %SO_RCVBUF settings 238 238 * @sk_lock: synchronizer 239 + * @sk_kern_sock: True if sock is using kernel lock classes 239 240 * @sk_rcvbuf: size of receive buffer in bytes 240 241 * @sk_wq: sock wait queue and async head 241 242 * @sk_rx_dst: receive input route used by early demux ··· 431 430 #endif 432 431 433 432 kmemcheck_bitfield_begin(flags); 434 - unsigned int sk_padding : 2, 433 + unsigned int sk_padding : 1, 434 + sk_kern_sock : 1, 435 435 sk_no_check_tx : 1, 436 436 sk_no_check_rx : 1, 437 437 sk_userlocks : 4, ··· 1017 1015 int addr_len); 1018 1016 int (*disconnect)(struct sock *sk, int flags); 1019 1017 1020 - struct sock * (*accept)(struct sock *sk, int flags, int *err); 1018 + struct sock * (*accept)(struct sock *sk, int flags, int *err, 1019 + bool kern); 1021 1020 1022 1021 int (*ioctl)(struct sock *sk, int cmd, 1023 1022 unsigned long arg); ··· 1576 1573 int sock_no_bind(struct socket *, struct sockaddr *, int); 1577 1574 int sock_no_connect(struct socket *, struct sockaddr *, int, int); 1578 1575 int sock_no_socketpair(struct socket *, struct socket *); 1579 - int sock_no_accept(struct socket *, struct socket *, int); 1576 + int sock_no_accept(struct socket *, struct socket *, int, bool); 1580 1577 int sock_no_getname(struct socket *, struct sockaddr *, int *, int); 1581 1578 unsigned int sock_no_poll(struct file *, struct socket *, 1582 1579 struct poll_table_struct *);
+3 -2
net/atm/svc.c
··· 318 318 return error; 319 319 } 320 320 321 - static int svc_accept(struct socket *sock, struct socket *newsock, int flags) 321 + static int svc_accept(struct socket *sock, struct socket *newsock, int flags, 322 + bool kern) 322 323 { 323 324 struct sock *sk = sock->sk; 324 325 struct sk_buff *skb; ··· 330 329 331 330 lock_sock(sk); 332 331 333 - error = svc_create(sock_net(sk), newsock, 0, 0); 332 + error = svc_create(sock_net(sk), newsock, 0, kern); 334 333 if (error) 335 334 goto out; 336 335
+2 -1
net/ax25/af_ax25.c
··· 1320 1320 return err; 1321 1321 } 1322 1322 1323 - static int ax25_accept(struct socket *sock, struct socket *newsock, int flags) 1323 + static int ax25_accept(struct socket *sock, struct socket *newsock, int flags, 1324 + bool kern) 1324 1325 { 1325 1326 struct sk_buff *skb; 1326 1327 struct sock *newsk;
+1 -1
net/bluetooth/l2cap_sock.c
··· 301 301 } 302 302 303 303 static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, 304 - int flags) 304 + int flags, bool kern) 305 305 { 306 306 DEFINE_WAIT_FUNC(wait, woken_wake_function); 307 307 struct sock *sk = sock->sk, *nsk;
+2 -1
net/bluetooth/rfcomm/sock.c
··· 471 471 return err; 472 472 } 473 473 474 - static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags) 474 + static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags, 475 + bool kern) 475 476 { 476 477 DEFINE_WAIT_FUNC(wait, woken_wake_function); 477 478 struct sock *sk = sock->sk, *nsk;
+1 -1
net/bluetooth/sco.c
··· 627 627 } 628 628 629 629 static int sco_sock_accept(struct socket *sock, struct socket *newsock, 630 - int flags) 630 + int flags, bool kern) 631 631 { 632 632 DEFINE_WAIT_FUNC(wait, woken_wake_function); 633 633 struct sock *sk = sock->sk, *ch;
+57 -49
net/core/sock.c
··· 197 197 198 198 /* 199 199 * Each address family might have different locking rules, so we have 200 - * one slock key per address family: 200 + * one slock key per address family and separate keys for internal and 201 + * userspace sockets. 201 202 */ 202 203 static struct lock_class_key af_family_keys[AF_MAX]; 204 + static struct lock_class_key af_family_kern_keys[AF_MAX]; 203 205 static struct lock_class_key af_family_slock_keys[AF_MAX]; 206 + static struct lock_class_key af_family_kern_slock_keys[AF_MAX]; 204 207 205 208 /* 206 209 * Make lock validator output more readable. (we pre-construct these 207 210 * strings build-time, so that runtime initialization of socket 208 211 * locks is fast): 209 212 */ 213 + 214 + #define _sock_locks(x) \ 215 + x "AF_UNSPEC", x "AF_UNIX" , x "AF_INET" , \ 216 + x "AF_AX25" , x "AF_IPX" , x "AF_APPLETALK", \ 217 + x "AF_NETROM", x "AF_BRIDGE" , x "AF_ATMPVC" , \ 218 + x "AF_X25" , x "AF_INET6" , x "AF_ROSE" , \ 219 + x "AF_DECnet", x "AF_NETBEUI" , x "AF_SECURITY" , \ 220 + x "AF_KEY" , x "AF_NETLINK" , x "AF_PACKET" , \ 221 + x "AF_ASH" , x "AF_ECONET" , x "AF_ATMSVC" , \ 222 + x "AF_RDS" , x "AF_SNA" , x "AF_IRDA" , \ 223 + x "AF_PPPOX" , x "AF_WANPIPE" , x "AF_LLC" , \ 224 + x "27" , x "28" , x "AF_CAN" , \ 225 + x "AF_TIPC" , x "AF_BLUETOOTH", x "IUCV" , \ 226 + x "AF_RXRPC" , x "AF_ISDN" , x "AF_PHONET" , \ 227 + x "AF_IEEE802154", x "AF_CAIF" , x "AF_ALG" , \ 228 + x "AF_NFC" , x "AF_VSOCK" , x "AF_KCM" , \ 229 + x "AF_QIPCRTR", x "AF_SMC" , x "AF_MAX" 230 + 210 231 static const char *const af_family_key_strings[AF_MAX+1] = { 211 - "sk_lock-AF_UNSPEC", "sk_lock-AF_UNIX" , "sk_lock-AF_INET" , 212 - "sk_lock-AF_AX25" , "sk_lock-AF_IPX" , "sk_lock-AF_APPLETALK", 213 - "sk_lock-AF_NETROM", "sk_lock-AF_BRIDGE" , "sk_lock-AF_ATMPVC" , 214 - "sk_lock-AF_X25" , "sk_lock-AF_INET6" , "sk_lock-AF_ROSE" , 215 - "sk_lock-AF_DECnet", "sk_lock-AF_NETBEUI" , "sk_lock-AF_SECURITY" , 216 - "sk_lock-AF_KEY" , "sk_lock-AF_NETLINK" , "sk_lock-AF_PACKET" , 217 - "sk_lock-AF_ASH" , "sk_lock-AF_ECONET" , "sk_lock-AF_ATMSVC" , 218 - "sk_lock-AF_RDS" , "sk_lock-AF_SNA" , "sk_lock-AF_IRDA" , 219 - "sk_lock-AF_PPPOX" , "sk_lock-AF_WANPIPE" , "sk_lock-AF_LLC" , 220 - "sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" , 221 - "sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" , 222 - "sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" , 223 - "sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , "sk_lock-AF_ALG" , 224 - "sk_lock-AF_NFC" , "sk_lock-AF_VSOCK" , "sk_lock-AF_KCM" , 225 - "sk_lock-AF_QIPCRTR", "sk_lock-AF_SMC" , "sk_lock-AF_MAX" 232 + _sock_locks("sk_lock-") 226 233 }; 227 234 static const char *const af_family_slock_key_strings[AF_MAX+1] = { 228 - "slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" , 229 - "slock-AF_AX25" , "slock-AF_IPX" , "slock-AF_APPLETALK", 230 - "slock-AF_NETROM", "slock-AF_BRIDGE" , "slock-AF_ATMPVC" , 231 - "slock-AF_X25" , "slock-AF_INET6" , "slock-AF_ROSE" , 232 - "slock-AF_DECnet", "slock-AF_NETBEUI" , "slock-AF_SECURITY" , 233 - "slock-AF_KEY" , "slock-AF_NETLINK" , "slock-AF_PACKET" , 234 - "slock-AF_ASH" , "slock-AF_ECONET" , "slock-AF_ATMSVC" , 235 - "slock-AF_RDS" , "slock-AF_SNA" , "slock-AF_IRDA" , 236 - "slock-AF_PPPOX" , "slock-AF_WANPIPE" , "slock-AF_LLC" , 237 - "slock-27" , "slock-28" , "slock-AF_CAN" , 238 - "slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" , 239 - "slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" , 240 - "slock-AF_IEEE802154", "slock-AF_CAIF" , "slock-AF_ALG" , 241 - "slock-AF_NFC" , "slock-AF_VSOCK" ,"slock-AF_KCM" , 242 - "slock-AF_QIPCRTR", "slock-AF_SMC" , "slock-AF_MAX" 235 + _sock_locks("slock-") 243 236 }; 244 237 static const char *const af_family_clock_key_strings[AF_MAX+1] = { 245 - "clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" , 246 - "clock-AF_AX25" , "clock-AF_IPX" , "clock-AF_APPLETALK", 247 - "clock-AF_NETROM", "clock-AF_BRIDGE" , "clock-AF_ATMPVC" , 248 - "clock-AF_X25" , "clock-AF_INET6" , "clock-AF_ROSE" , 249 - "clock-AF_DECnet", "clock-AF_NETBEUI" , "clock-AF_SECURITY" , 250 - "clock-AF_KEY" , "clock-AF_NETLINK" , "clock-AF_PACKET" , 251 - "clock-AF_ASH" , "clock-AF_ECONET" , "clock-AF_ATMSVC" , 252 - "clock-AF_RDS" , "clock-AF_SNA" , "clock-AF_IRDA" , 253 - "clock-AF_PPPOX" , "clock-AF_WANPIPE" , "clock-AF_LLC" , 254 - "clock-27" , "clock-28" , "clock-AF_CAN" , 255 - "clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" , 256 - "clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" , 257 - "clock-AF_IEEE802154", "clock-AF_CAIF" , "clock-AF_ALG" , 258 - "clock-AF_NFC" , "clock-AF_VSOCK" , "clock-AF_KCM" , 259 - "clock-AF_QIPCRTR", "clock-AF_SMC" , "clock-AF_MAX" 238 + _sock_locks("clock-") 239 + }; 240 + 241 + static const char *const af_family_kern_key_strings[AF_MAX+1] = { 242 + _sock_locks("k-sk_lock-") 243 + }; 244 + static const char *const af_family_kern_slock_key_strings[AF_MAX+1] = { 245 + _sock_locks("k-slock-") 246 + }; 247 + static const char *const af_family_kern_clock_key_strings[AF_MAX+1] = { 248 + _sock_locks("k-clock-") 260 249 }; 261 250 262 251 /* ··· 253 264 * so split the lock classes by using a per-AF key: 254 265 */ 255 266 static struct lock_class_key af_callback_keys[AF_MAX]; 267 + static struct lock_class_key af_kern_callback_keys[AF_MAX]; 256 268 257 269 /* Take into consideration the size of the struct sk_buff overhead in the 258 270 * determination of these values, since that is non-constant across ··· 1283 1293 */ 1284 1294 static inline void sock_lock_init(struct sock *sk) 1285 1295 { 1286 - sock_lock_init_class_and_name(sk, 1296 + if (sk->sk_kern_sock) 1297 + sock_lock_init_class_and_name( 1298 + sk, 1299 + af_family_kern_slock_key_strings[sk->sk_family], 1300 + af_family_kern_slock_keys + sk->sk_family, 1301 + af_family_kern_key_strings[sk->sk_family], 1302 + af_family_kern_keys + sk->sk_family); 1303 + else 1304 + sock_lock_init_class_and_name( 1305 + sk, 1287 1306 af_family_slock_key_strings[sk->sk_family], 1288 1307 af_family_slock_keys + sk->sk_family, 1289 1308 af_family_key_strings[sk->sk_family], ··· 1398 1399 * why we need sk_prot_creator -acme 1399 1400 */ 1400 1401 sk->sk_prot = sk->sk_prot_creator = prot; 1402 + sk->sk_kern_sock = kern; 1401 1403 sock_lock_init(sk); 1402 1404 sk->sk_net_refcnt = kern ? 0 : 1; 1403 1405 if (likely(sk->sk_net_refcnt)) ··· 2277 2277 } 2278 2278 EXPORT_SYMBOL(sock_no_socketpair); 2279 2279 2280 - int sock_no_accept(struct socket *sock, struct socket *newsock, int flags) 2280 + int sock_no_accept(struct socket *sock, struct socket *newsock, int flags, 2281 + bool kern) 2281 2282 { 2282 2283 return -EOPNOTSUPP; 2283 2284 } ··· 2482 2481 } 2483 2482 2484 2483 rwlock_init(&sk->sk_callback_lock); 2485 - lockdep_set_class_and_name(&sk->sk_callback_lock, 2484 + if (sk->sk_kern_sock) 2485 + lockdep_set_class_and_name( 2486 + &sk->sk_callback_lock, 2487 + af_kern_callback_keys + sk->sk_family, 2488 + af_family_kern_clock_key_strings[sk->sk_family]); 2489 + else 2490 + lockdep_set_class_and_name( 2491 + &sk->sk_callback_lock, 2486 2492 af_callback_keys + sk->sk_family, 2487 2493 af_family_clock_key_strings[sk->sk_family]); 2488 2494
+3 -2
net/decnet/af_decnet.c
··· 1070 1070 return skb == NULL ? ERR_PTR(err) : skb; 1071 1071 } 1072 1072 1073 - static int dn_accept(struct socket *sock, struct socket *newsock, int flags) 1073 + static int dn_accept(struct socket *sock, struct socket *newsock, int flags, 1074 + bool kern) 1074 1075 { 1075 1076 struct sock *sk = sock->sk, *newsk; 1076 1077 struct sk_buff *skb = NULL; ··· 1100 1099 1101 1100 cb = DN_SKB_CB(skb); 1102 1101 sk->sk_ack_backlog--; 1103 - newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, 0); 1102 + newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, kern); 1104 1103 if (newsk == NULL) { 1105 1104 release_sock(sk); 1106 1105 kfree_skb(skb);
+3 -2
net/ipv4/af_inet.c
··· 689 689 * Accept a pending connection. The TCP layer now gives BSD semantics. 690 690 */ 691 691 692 - int inet_accept(struct socket *sock, struct socket *newsock, int flags) 692 + int inet_accept(struct socket *sock, struct socket *newsock, int flags, 693 + bool kern) 693 694 { 694 695 struct sock *sk1 = sock->sk; 695 696 int err = -EINVAL; 696 - struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err); 697 + struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err, kern); 697 698 698 699 if (!sk2) 699 700 goto do_err;
+1 -1
net/ipv4/inet_connection_sock.c
··· 424 424 /* 425 425 * This will accept the next outstanding connection. 426 426 */ 427 - struct sock *inet_csk_accept(struct sock *sk, int flags, int *err) 427 + struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) 428 428 { 429 429 struct inet_connection_sock *icsk = inet_csk(sk); 430 430 struct request_sock_queue *queue = &icsk->icsk_accept_queue;
+3 -2
net/irda/af_irda.c
··· 828 828 * Wait for incoming connection 829 829 * 830 830 */ 831 - static int irda_accept(struct socket *sock, struct socket *newsock, int flags) 831 + static int irda_accept(struct socket *sock, struct socket *newsock, int flags, 832 + bool kern) 832 833 { 833 834 struct sock *sk = sock->sk; 834 835 struct irda_sock *new, *self = irda_sk(sk); ··· 837 836 struct sk_buff *skb = NULL; 838 837 int err; 839 838 840 - err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0); 839 + err = irda_create(sock_net(sk), newsock, sk->sk_protocol, kern); 841 840 if (err) 842 841 return err; 843 842
+1 -1
net/iucv/af_iucv.c
··· 938 938 939 939 /* Accept a pending connection */ 940 940 static int iucv_sock_accept(struct socket *sock, struct socket *newsock, 941 - int flags) 941 + int flags, bool kern) 942 942 { 943 943 DECLARE_WAITQUEUE(wait, current); 944 944 struct sock *sk = sock->sk, *nsk;
+3 -1
net/llc/af_llc.c
··· 641 641 * @sock: Socket which connections arrive on. 642 642 * @newsock: Socket to move incoming connection to. 643 643 * @flags: User specified operational flags. 644 + * @kern: If the socket is kernel internal 644 645 * 645 646 * Accept a new incoming connection. 646 647 * Returns 0 upon success, negative otherwise. 647 648 */ 648 - static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags) 649 + static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags, 650 + bool kern) 649 651 { 650 652 struct sock *sk = sock->sk, *newsk; 651 653 struct llc_sock *llc, *newllc;
+2 -1
net/netrom/af_netrom.c
··· 765 765 return err; 766 766 } 767 767 768 - static int nr_accept(struct socket *sock, struct socket *newsock, int flags) 768 + static int nr_accept(struct socket *sock, struct socket *newsock, int flags, 769 + bool kern) 769 770 { 770 771 struct sk_buff *skb; 771 772 struct sock *newsk;
+1 -1
net/nfc/llcp_sock.c
··· 441 441 } 442 442 443 443 static int llcp_sock_accept(struct socket *sock, struct socket *newsock, 444 - int flags) 444 + int flags, bool kern) 445 445 { 446 446 DECLARE_WAITQUEUE(wait, current); 447 447 struct sock *sk = sock->sk, *new_sk;
+4 -2
net/phonet/pep.c
··· 772 772 sock_put(sk); 773 773 } 774 774 775 - static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp) 775 + static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp, 776 + bool kern) 776 777 { 777 778 struct pep_sock *pn = pep_sk(sk), *newpn; 778 779 struct sock *newsk = NULL; ··· 847 846 } 848 847 849 848 /* Create a new to-be-accepted sock */ 850 - newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot, 0); 849 + newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot, 850 + kern); 851 851 if (!newsk) { 852 852 pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL); 853 853 err = -ENOBUFS;
+2 -2
net/phonet/socket.c
··· 305 305 } 306 306 307 307 static int pn_socket_accept(struct socket *sock, struct socket *newsock, 308 - int flags) 308 + int flags, bool kern) 309 309 { 310 310 struct sock *sk = sock->sk; 311 311 struct sock *newsk; ··· 314 314 if (unlikely(sk->sk_state != TCP_LISTEN)) 315 315 return -EINVAL; 316 316 317 - newsk = sk->sk_prot->accept(sk, flags, &err); 317 + newsk = sk->sk_prot->accept(sk, flags, &err, kern); 318 318 if (!newsk) 319 319 return err; 320 320
+1 -1
net/rds/tcp_listen.c
··· 133 133 134 134 new_sock->type = sock->type; 135 135 new_sock->ops = sock->ops; 136 - ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); 136 + ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true); 137 137 if (ret < 0) 138 138 goto out; 139 139
+2 -1
net/rose/af_rose.c
··· 871 871 return err; 872 872 } 873 873 874 - static int rose_accept(struct socket *sock, struct socket *newsock, int flags) 874 + static int rose_accept(struct socket *sock, struct socket *newsock, int flags, 875 + bool kern) 875 876 { 876 877 struct sk_buff *skb; 877 878 struct sock *newsk;
+3 -2
net/sctp/ipv6.c
··· 640 640 641 641 /* Create and initialize a new sk for the socket to be returned by accept(). */ 642 642 static struct sock *sctp_v6_create_accept_sk(struct sock *sk, 643 - struct sctp_association *asoc) 643 + struct sctp_association *asoc, 644 + bool kern) 644 645 { 645 646 struct sock *newsk; 646 647 struct ipv6_pinfo *newnp, *np = inet6_sk(sk); 647 648 struct sctp6_sock *newsctp6sk; 648 649 struct ipv6_txoptions *opt; 649 650 650 - newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, 0); 651 + newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, kern); 651 652 if (!newsk) 652 653 goto out; 653 654
+3 -2
net/sctp/protocol.c
··· 575 575 576 576 /* Create and initialize a new sk for the socket returned by accept(). */ 577 577 static struct sock *sctp_v4_create_accept_sk(struct sock *sk, 578 - struct sctp_association *asoc) 578 + struct sctp_association *asoc, 579 + bool kern) 579 580 { 580 581 struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL, 581 - sk->sk_prot, 0); 582 + sk->sk_prot, kern); 582 583 struct inet_sock *newinet; 583 584 584 585 if (!newsk)
+2 -2
net/sctp/socket.c
··· 4116 4116 * descriptor will be returned from accept() to represent the newly 4117 4117 * formed association. 4118 4118 */ 4119 - static struct sock *sctp_accept(struct sock *sk, int flags, int *err) 4119 + static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern) 4120 4120 { 4121 4121 struct sctp_sock *sp; 4122 4122 struct sctp_endpoint *ep; ··· 4151 4151 */ 4152 4152 asoc = list_entry(ep->asocs.next, struct sctp_association, asocs); 4153 4153 4154 - newsk = sp->pf->create_accept_sk(sk, asoc); 4154 + newsk = sp->pf->create_accept_sk(sk, asoc, kern); 4155 4155 if (!newsk) { 4156 4156 error = -ENOMEM; 4157 4157 goto out;
+1 -1
net/smc/af_smc.c
··· 944 944 } 945 945 946 946 static int smc_accept(struct socket *sock, struct socket *new_sock, 947 - int flags) 947 + int flags, bool kern) 948 948 { 949 949 struct sock *sk = sock->sk, *nsk; 950 950 DECLARE_WAITQUEUE(wait, current);
+2 -2
net/socket.c
··· 1506 1506 if (err) 1507 1507 goto out_fd; 1508 1508 1509 - err = sock->ops->accept(sock, newsock, sock->file->f_flags); 1509 + err = sock->ops->accept(sock, newsock, sock->file->f_flags, false); 1510 1510 if (err < 0) 1511 1511 goto out_fd; 1512 1512 ··· 3239 3239 if (err < 0) 3240 3240 goto done; 3241 3241 3242 - err = sock->ops->accept(sock, *newsock, flags); 3242 + err = sock->ops->accept(sock, *newsock, flags, true); 3243 3243 if (err < 0) { 3244 3244 sock_release(*newsock); 3245 3245 *newsock = NULL;
+5 -3
net/tipc/socket.c
··· 115 115 static void tipc_write_space(struct sock *sk); 116 116 static void tipc_sock_destruct(struct sock *sk); 117 117 static int tipc_release(struct socket *sock); 118 - static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); 118 + static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, 119 + bool kern); 119 120 static void tipc_sk_timeout(unsigned long data); 120 121 static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, 121 122 struct tipc_name_seq const *seq); ··· 2030 2029 * 2031 2030 * Returns 0 on success, errno otherwise 2032 2031 */ 2033 - static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) 2032 + static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, 2033 + bool kern) 2034 2034 { 2035 2035 struct sock *new_sk, *sk = sock->sk; 2036 2036 struct sk_buff *buf; ··· 2053 2051 2054 2052 buf = skb_peek(&sk->sk_receive_queue); 2055 2053 2056 - res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 0); 2054 + res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, kern); 2057 2055 if (res) 2058 2056 goto exit; 2059 2057 security_sk_clone(sock->sk, new_sock->sk);
+3 -2
net/unix/af_unix.c
··· 636 636 static int unix_stream_connect(struct socket *, struct sockaddr *, 637 637 int addr_len, int flags); 638 638 static int unix_socketpair(struct socket *, struct socket *); 639 - static int unix_accept(struct socket *, struct socket *, int); 639 + static int unix_accept(struct socket *, struct socket *, int, bool); 640 640 static int unix_getname(struct socket *, struct sockaddr *, int *, int); 641 641 static unsigned int unix_poll(struct file *, struct socket *, poll_table *); 642 642 static unsigned int unix_dgram_poll(struct file *, struct socket *, ··· 1402 1402 set_bit(SOCK_PASSSEC, &new->flags); 1403 1403 } 1404 1404 1405 - static int unix_accept(struct socket *sock, struct socket *newsock, int flags) 1405 + static int unix_accept(struct socket *sock, struct socket *newsock, int flags, 1406 + bool kern) 1406 1407 { 1407 1408 struct sock *sk = sock->sk; 1408 1409 struct sock *tsk;
+2 -1
net/vmw_vsock/af_vsock.c
··· 1250 1250 return err; 1251 1251 } 1252 1252 1253 - static int vsock_accept(struct socket *sock, struct socket *newsock, int flags) 1253 + static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, 1254 + bool kern) 1254 1255 { 1255 1256 struct sock *listener; 1256 1257 int err;
+2 -1
net/x25/af_x25.c
··· 852 852 return rc; 853 853 } 854 854 855 - static int x25_accept(struct socket *sock, struct socket *newsock, int flags) 855 + static int x25_accept(struct socket *sock, struct socket *newsock, int flags, 856 + bool kern) 856 857 { 857 858 struct sock *sk = sock->sk; 858 859 struct sock *newsk;