Skip to content

Commit 9d793b0

Browse files
Alan Coxtorvalds
authored andcommitted
i2o: Fix 32/64bit DMA locking
The I2O ioctls assume 32bits. In itself that is fine as they are old cards and nobody uses 64bit. However on LKML it was noted this assumption is also made for allocated memory and is unsafe on 64bit systems. Fixing this is a mess. It turns out there is tons of crap buried in a header file that does racy 32/64bit filtering on the masks. So we: - Verify all callers of the racy code can sleep (i2o_dma_[re]alloc) - Move the code into a new i2o/memory.c file - Remove the gfp_mask argument so nobody can try and misuse the function - Wrap a mutex around the problem area (a single mutex is easy to do and none of this is performance relevant) - Switch the remaining problem kmalloc holdout to use i2o_dma_alloc Cc: Markus Lidel <Markus.Lidel@shadowconnect.com> Cc: Vasily Averin <vvs@sw.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 673c0c0 commit 9d793b0

8 files changed

Lines changed: 351 additions & 311 deletions

File tree

‎drivers/message/i2o/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# In the future, some of these should be built conditionally.
66
#
77

8-
i2o_core-y += iop.o driver.o device.o debug.o pci.o exec-osm.o
8+
i2o_core-y += iop.o driver.o device.o debug.o pci.o exec-osm.o memory.o
99
i2o_bus-y += bus-osm.o
1010
i2o_config-y += config-osm.o
1111
obj-$(CONFIG_I2O) += i2o_core.o

‎drivers/message/i2o/device.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
467467

468468
res.virt = NULL;
469469

470-
if (i2o_dma_alloc(dev, &res, reslen, GFP_KERNEL))
470+
if (i2o_dma_alloc(dev, &res, reslen))
471471
return -ENOMEM;
472472

473473
msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);

‎drivers/message/i2o/exec-osm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)
388388

389389
dev = &c->pdev->dev;
390390

391-
if (i2o_dma_realloc
392-
(dev, &c->dlct, le32_to_cpu(sb->expected_lct_size), GFP_KERNEL))
391+
if (i2o_dma_realloc(dev, &c->dlct,
392+
le32_to_cpu(sb->expected_lct_size)))
393393
return -ENOMEM;
394394

395395
msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);

‎drivers/message/i2o/i2o_config.c‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static int i2o_cfg_swdl(unsigned long arg)
260260
if (IS_ERR(msg))
261261
return PTR_ERR(msg);
262262

263-
if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
263+
if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
264264
i2o_msg_nop(c, msg);
265265
return -ENOMEM;
266266
}
@@ -339,7 +339,7 @@ static int i2o_cfg_swul(unsigned long arg)
339339
if (IS_ERR(msg))
340340
return PTR_ERR(msg);
341341

342-
if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
342+
if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
343343
i2o_msg_nop(c, msg);
344344
return -ENOMEM;
345345
}
@@ -634,9 +634,7 @@ static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
634634
sg_size = sg[i].flag_count & 0xffffff;
635635
p = &(sg_list[sg_index]);
636636
/* Allocate memory for the transfer */
637-
if (i2o_dma_alloc
638-
(&c->pdev->dev, p, sg_size,
639-
PCI_DMA_BIDIRECTIONAL)) {
637+
if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
640638
printk(KERN_DEBUG
641639
"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
642640
c->name, sg_size, i, sg_count);
@@ -780,12 +778,11 @@ static int i2o_cfg_passthru(unsigned long arg)
780778
u32 size = 0;
781779
u32 reply_size = 0;
782780
u32 rcode = 0;
783-
void *sg_list[SG_TABLESIZE];
781+
struct i2o_dma sg_list[SG_TABLESIZE];
784782
u32 sg_offset = 0;
785783
u32 sg_count = 0;
786784
int sg_index = 0;
787785
u32 i = 0;
788-
void *p = NULL;
789786
i2o_status_block *sb;
790787
struct i2o_message *msg;
791788
unsigned int iop;
@@ -842,6 +839,7 @@ static int i2o_cfg_passthru(unsigned long arg)
842839
memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
843840
if (sg_offset) {
844841
struct sg_simple_element *sg;
842+
struct i2o_dma *p;
845843

846844
if (sg_offset * 4 >= size) {
847845
rcode = -EFAULT;
@@ -871,22 +869,22 @@ static int i2o_cfg_passthru(unsigned long arg)
871869
goto sg_list_cleanup;
872870
}
873871
sg_size = sg[i].flag_count & 0xffffff;
872+
p = &(sg_list[sg_index]);
873+
if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
874874
/* Allocate memory for the transfer */
875-
p = kmalloc(sg_size, GFP_KERNEL);
876-
if (!p) {
877875
printk(KERN_DEBUG
878876
"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
879877
c->name, sg_size, i, sg_count);
880878
rcode = -ENOMEM;
881879
goto sg_list_cleanup;
882880
}
883-
sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
881+
sg_index++;
884882
/* Copy in the user's SG buffer if necessary */
885883
if (sg[i].
886884
flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
887885
// TODO 64bit fix
888886
if (copy_from_user
889-
(p, (void __user *)sg[i].addr_bus,
887+
(p->virt, (void __user *)sg[i].addr_bus,
890888
sg_size)) {
891889
printk(KERN_DEBUG
892890
"%s: Could not copy SG buf %d FROM user\n",
@@ -895,8 +893,7 @@ static int i2o_cfg_passthru(unsigned long arg)
895893
goto sg_list_cleanup;
896894
}
897895
}
898-
//TODO 64bit fix
899-
sg[i].addr_bus = virt_to_bus(p);
896+
sg[i].addr_bus = p->phys;
900897
}
901898
}
902899

@@ -908,7 +905,7 @@ static int i2o_cfg_passthru(unsigned long arg)
908905
}
909906

910907
if (sg_offset) {
911-
u32 rmsg[128];
908+
u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
912909
/* Copy back the Scatter Gather buffers back to user space */
913910
u32 j;
914911
// TODO 64bit fix
@@ -942,11 +939,11 @@ static int i2o_cfg_passthru(unsigned long arg)
942939
sg_size = sg[j].flag_count & 0xffffff;
943940
// TODO 64bit fix
944941
if (copy_to_user
945-
((void __user *)sg[j].addr_bus, sg_list[j],
942+
((void __user *)sg[j].addr_bus, sg_list[j].virt,
946943
sg_size)) {
947944
printk(KERN_WARNING
948945
"%s: Could not copy %p TO user %x\n",
949-
c->name, sg_list[j],
946+
c->name, sg_list[j].virt,
950947
sg[j].addr_bus);
951948
rcode = -EFAULT;
952949
goto sg_list_cleanup;
@@ -973,7 +970,7 @@ static int i2o_cfg_passthru(unsigned long arg)
973970
}
974971

975972
for (i = 0; i < sg_index; i++)
976-
kfree(sg_list[i]);
973+
i2o_dma_free(&c->pdev->dev, &sg_list[i]);
977974

978975
cleanup:
979976
kfree(reply);

‎drivers/message/i2o/iop.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ static int i2o_hrt_get(struct i2o_controller *c)
10041004

10051005
size = hrt->num_entries * hrt->entry_len << 2;
10061006
if (size > c->hrt.len) {
1007-
if (i2o_dma_realloc(dev, &c->hrt, size, GFP_KERNEL))
1007+
if (i2o_dma_realloc(dev, &c->hrt, size))
10081008
return -ENOMEM;
10091009
else
10101010
hrt = c->hrt.virt;

0 commit comments

Comments
 (0)