From patchwork Sat Jun 25 04:08:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hariprasad Shenai X-Patchwork-Id: 640531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rc1n66qZzz9s8d for ; Sat, 25 Jun 2016 14:04:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750961AbcFYEEi (ORCPT ); Sat, 25 Jun 2016 00:04:38 -0400 Received: from [12.32.117.8] ([12.32.117.8]:59743 "EHLO stargate3.asicdesigners.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750723AbcFYEEi (ORCPT ); Sat, 25 Jun 2016 00:04:38 -0400 Received: from gill.asicdesigners.com.com ([10.193.186.211]) by stargate3.asicdesigners.com (8.13.8/8.13.8) with ESMTP id u5P43baU010555; Fri, 24 Jun 2016 21:03:48 -0700 From: Hariprasad Shenai To: bhelgaas@google.com Cc: linux-pci@vger.kernel.org, leedom@chelsio.com, swise@opengridcomputing.com, Hariprasad Shenai Subject: [PATCH] pci: Use same logic in pci_vpd_read as that of pci_vpd_write Date: Sat, 25 Jun 2016 09:38:42 +0530 Message-Id: <1466827722-17287-1-git-send-email-hariprasad@chelsio.com> X-Mailer: git-send-email 2.3.4 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 Signed-off-by: Hariprasad Shenai --- 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;