All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pci: Use same logic in pci_vpd_read as that of pci_vpd_write
@ 2016-06-25  4:08 Hariprasad Shenai
  2016-08-08 21:08 ` Bjorn Helgaas
  0 siblings, 1 reply; 5+ messages in thread
From: Hariprasad Shenai @ 2016-06-25  4:08 UTC (permalink / raw)
  To: bhelgaas; +Cc: linux-pci, leedom, swise, Hariprasad Shenai

The new implementation of pci_read_vpd() silently fails to perform a VPD
read and allows the caller to use random stack garbage in the read buffer
without knowing that it's not really VPD contents. If any portion of the
VPD read isn't going to be performed, we should signal that back to the
caller.  We could either return an error or we could return the number of
bytes actually read. The problem with the latter is that it would require
changing every single caller to check for Requested Read Length == Actual
Read Length. Returning an error is the more conservative fix and allows
for rapid diagnosis of problems.

Signed-off-by: Casey Leedom <leedom@chelsio.com>
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
---
 drivers/pci/access.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index d11cdbb8fba3..113637de79bf 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -405,13 +405,8 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
 	if (vpd->len == 0)
 		return -EIO;
 
-	if (pos > vpd->len)
-		return 0;
-
-	if (end > vpd->len) {
-		end = vpd->len;
-		count = end - pos;
-	}
+	if (end > vpd->len)
+		return -EINVAL;
 
 	if (mutex_lock_killable(&vpd->lock))
 		return -EINTR;
-- 
2.3.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-13 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-25  4:08 [PATCH] pci: Use same logic in pci_vpd_read as that of pci_vpd_write Hariprasad Shenai
2016-08-08 21:08 ` Bjorn Helgaas
2016-08-08 21:20   ` Casey Leedom
2016-08-18 20:55     ` Bjorn Helgaas
2016-09-13 22:16       ` Casey Leedom

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.