]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
rapidio: avoid data race between file operation callbacks and mport_cdev_add().
authorMadhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Thu, 4 Jun 2020 23:51:21 +0000 (16:51 -0700)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 9 Nov 2020 13:47:54 +0000 (14:47 +0100)
commit74c1793f5522a35f2c05b0075f5afeee6270f3c7
tree54b04f5ccacace5a886e3b83b7a6f9fff00dfffa
parenta4e242b102476c81d69e666dc8e997dad6d7b200
rapidio: avoid data race between file operation callbacks and mport_cdev_add().

BugLink: https://bugs.launchpad.net/bugs/1900624
[ Upstream commit e1c3cdb26ab881b77486dc50370356a349077c74 ]

Fields of md(mport_dev) are set after cdev_device_add().  However, the
file operation callbacks can be called after cdev_device_add() and
therefore accesses to fields of md in the callbacks can race with the rest
of the mport_cdev_add() function.

One such example is INIT_LIST_HEAD(&md->portwrites) in mport_cdev_add(),
the list is initialised after cdev_device_add().  This can race with
list_add_tail(&pw_filter->md_node,&md->portwrites) in
rio_mport_add_pw_filter() which is called by unlocked_ioctl.

To avoid such data races use cdev_device_add() after initializing md.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Alexandre Bounine <alex.bou9@gmail.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Mike Marshall <hubcap@omnibond.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Allison Randal <allison@lohutok.net>
Cc: Pavel Andrianov <andrianov@ispras.ru>
Link: http://lkml.kernel.org/r/20200426112950.1803-1-madhuparnabhowmik10@gmail.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Ian May <ian.may@canonical.com>
drivers/rapidio/devices/rio_mport_cdev.c