Skip to content

Commit 8c9edf6

Browse files
Allen Hubbejonmason
authored andcommitted
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>
1 parent 8b5a22d commit 8c9edf6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/ntb/ntb_transport.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,16 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
629629
}
630630

631631
static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
632-
unsigned int size)
632+
resource_size_t size)
633633
{
634634
struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
635635
struct pci_dev *pdev = nt->ndev->pdev;
636-
unsigned int xlat_size, buff_size;
636+
size_t xlat_size, buff_size;
637637
int rc;
638638

639+
if (!size)
640+
return -EINVAL;
641+
639642
xlat_size = round_up(size, mw->xlat_align_size);
640643
buff_size = round_up(size, mw->xlat_align);
641644

@@ -655,7 +658,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
655658
if (!mw->virt_addr) {
656659
mw->xlat_size = 0;
657660
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",
659662
buff_size);
660663
return -ENOMEM;
661664
}

0 commit comments

Comments
 (0)