1
0
Fork 0
remarkable-linux/drivers/staging
David Howells cdfbabfb2f 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>
2017-03-09 18:23:27 -08:00
..
android sched/headers: Prepare to move the task_lock()/unlock() APIs to <linux/sched/task.h> 2017-03-02 08:42:38 +01:00
bcm2835-audio Staging: bcm2835-audio: fixed a code style issue: 2017-02-16 10:20:07 -08:00
board staging: board: Remove calls to of_genpd_get_from_provider() 2016-09-13 02:49:33 +02:00
clocking-wizard staging: clocking-wizard: Fix incorrect type of speed grade 2016-10-25 09:54:32 +02:00
comedi sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
dgnc sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
emxx_udc staging: emxx_udc: Fix CamelCase variable name 2017-01-03 16:42:22 +01:00
fbtft staging: fbtft: fix unaligned parentheses 2017-02-05 18:31:04 +01:00
fsl-mc staging: fsl-mc: fix warning in DT ranges parser 2017-03-01 09:23:56 +01:00
fwserial Staging: fwserial: remove unused function fill_unplug_req 2016-10-16 10:25:09 +02:00
gdm724x staging: gdm724x: fix incorrect type in assignment 2017-02-09 13:10:21 +01:00
goldfish
greybus sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
gs_fpgaboot scripts/spelling.txt: add "followings" pattern and fix typo instances 2017-02-27 18:43:47 -08:00
iio Staging: iio: adc: ad7816: fix symbolic permissions coding style issue 2017-01-28 12:22:07 +00:00
ks7010 staging/iio driver patches for 4.11-rc1 2017-02-22 12:14:01 -08:00
lustre net: Work around lockdep limitation in sockets that use sockets 2017-03-09 18:23:27 -08:00
media Staging/IIO driver fixes for 4.11-rc1 2017-03-04 11:26:18 -08:00
most staging: most: dim2_hdm octal permissions fix 2017-02-09 13:10:20 +01:00
mt29f_spinand
netlogic net: Remove usage of net_device last_rx member 2017-01-18 17:22:49 -05:00
nvec staging:nvec:nvec_ps2.c: Prefering kzalloc(sizeof(*ser_dev)...) over kzalloc(sizeof(struct serio)...) 2017-02-14 09:26:26 -08:00
octeon staging/iio driver patches for 4.11-rc1 2017-02-22 12:14:01 -08:00
octeon-usb staging: octeon-usb: Remove unnecessary assignment 2016-09-22 11:54:48 +02:00
olpc_dcon staging: olpc_dcon: olpc_dcon_xo_1_5: Remove multiple blank lines. 2017-01-10 17:40:15 +01:00
rtl8188eu sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
rtl8192e staging/iio driver patches for 4.11-rc1 2017-02-22 12:14:01 -08:00
rtl8192u scripts/spelling.txt: add "swithc" pattern and fix typo instances 2017-02-27 18:43:46 -08:00
rtl8712 sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
rts5208 staging: rts5208: remove unncessary result set and check, just return SUCCESS 2017-02-03 13:01:36 +01:00
skein staging: skein: fix checkpatch block comments warning 2017-01-20 14:39:12 +01:00
sm750fb Staging: sm750fb: sm750.c - style fix 2017-02-12 13:22:08 +01:00
speakup sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
unisys staging/iio driver patches for 4.11-rc1 2017-02-22 12:14:01 -08:00
vc04_services Staging/IIO driver fixes for 4.11-rc1 2017-03-04 11:26:18 -08:00
vme staging: vme: vme_user.c: fix warning 'line over 80 characters' 2017-01-16 18:08:56 +01:00
vt6655 staging:vt6656:baseband.h: fix function definition argument without identifier name issue 2017-02-10 15:06:44 +01:00
vt6656 staging: vt6656: rxtx.c Removed multiple dereferencing 2017-02-16 10:23:09 -08:00
wilc1000 scripts/spelling.txt: add "deintialize(d)" pattern and fix typo instances 2017-02-27 18:43:47 -08:00
wlan-ng staging/iio driver patches for 4.11-rc1 2017-02-22 12:14:01 -08:00
xgifb staging:xgifb:vb_setmode.h: Add missing identifier names 2017-02-12 13:55:28 -08:00
Kconfig staging: bcm2835-audio: initial staging submission 2017-01-27 09:44:31 +01:00
Makefile staging: bcm2835-audio: initial staging submission 2017-01-27 09:44:31 +01:00