[PATCH v2 2/6] PCI/proc: Serialize config inode size updates

Ziming Du <[email protected]>
Newsgroups org.kernel.vger.linux-pci,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
proc_bus_pci_write() calls i_size_write() without serializing concurrent
writers. On 32-bit SMP systems, concurrent updates can corrupt
i_size_seqcount and make later i_size_read() calls spin indefinitely.

Protect the inode size update with the inode lock, as required by
i_size_write().

Fixes: ecb3908046ce ("pci: write file size to inode on proc bus file write")
Signed-off-by: Ziming Du <[email protected]>
---
 drivers/pci/proc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index cad749924dd89..ec2338c1e667e 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -181,7 +181,9 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
 	pci_config_pm_runtime_put(dev);
 
 	*ppos = pos;
+	inode_lock(ino);
 	i_size_write(ino, dev->cfg_size);
+	inode_unlock(ino);
 	return nbytes;
 }
 
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.