aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen Hubbe <Allen.Hubbe@emc.com>2015-07-13 08:07:13 -0400
committerJon Mason <jdmason@kudzu.us>2015-08-09 16:32:22 -0400
commit8c9edf63e75f036b42afb4502deb20bbfb5004b4 (patch)
treee1a20719e91d54e26384642d8665854b44cb7ed7
parent8b5a22d8f18496f5921ccb92554a7051cbfd9b0c (diff)
NTB: Fix zero size or integer overflow in ntb_set_mw
A plain 32 bit integer will overflow for values over 4GiB. Change the plain integer size to the appropriate size type in ntb_set_mw. Change the type of the size parameter and two local variables used for size. Even if there is no overflow, a size of zero is invalid here. Reported-by: Juyoung Jung <jjung@micron.com> Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
-rw-r--r--drivers/ntb/ntb_transport.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index b82171e3e07d..bc556e2d7f62 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -629,13 +629,16 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
629} 629}
630 630
631static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, 631static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
632 unsigned int size) 632 resource_size_t size)
633{ 633{
634 struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; 634 struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
635 struct pci_dev *pdev = nt->ndev->pdev; 635 struct pci_dev *pdev = nt->ndev->pdev;
636 unsigned int xlat_size, buff_size; 636 size_t xlat_size, buff_size;
637 int rc; 637 int rc;
638 638
639 if (!size)
640 return -EINVAL;
641
639 xlat_size = round_up(size, mw->xlat_align_size); 642 xlat_size = round_up(size, mw->xlat_align_size);
640 buff_size = round_up(size, mw->xlat_align); 643 buff_size = round_up(size, mw->xlat_align);
641 644
@@ -655,7 +658,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
655 if (!mw->virt_addr) { 658 if (!mw->virt_addr) {
656 mw->xlat_size = 0; 659 mw->xlat_size = 0;
657 mw->buff_size = 0; 660 mw->buff_size = 0;
658 dev_err(&pdev->dev, "Unable to alloc MW buff of size %d\n", 661 dev_err(&pdev->dev, "Unable to alloc MW buff of size %zu\n",
659 buff_size); 662 buff_size);
660 return -ENOMEM; 663 return -ENOMEM;
661 } 664 }