RDMA/siw: fix pointer cast warning
Subsystems (2)
PATCH 1/1 RDMA/siw: fix pointer cast warning
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit dma_addr_t on 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
32 | return virt_to_page((void *)paddr);
| ^
Use the same double cast here that the driver uses elsewhere to convert between dma_addr_t and void*.
It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +1 -1
@@ -29,7 +29,7 @@ static struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx)dma_addr_t paddr =siw_pbl_get_buffer (pbl, offset,NULL , idx);if (paddr) -return virt_to_page ((void *)paddr); +return virt_to_page ((void *)(uintptr_t )paddr);return NULL ; }
Signature · 1 line
2.35.1
Quoted 50 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Thursday, 15 December 2022 18:04
To: Bernard Metzler <[email protected]>; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; Linus Walleij <[email protected]>
Cc: Arnd Bergmann <[email protected]>; [email protected]; linux- [email protected]
Subject: [EXTERNAL] [PATCH] RDMA/siw: fix pointer cast warningFrom: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
Fixes 0d1b756acf60 ("RDMA/siw: Pass a pointer to virt_to_page()")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/infiniband/sw/siw/siw_qp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/sw/siw/siw_qp_tx.c +1
-1@@ -29,7 +29,7 @@ static struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx) dma_addr_t paddr = siw_pbl_get_buffer(pbl, offset, NULL, idx);if (paddr) -return virt_to_page ((void *)paddr); +return virt_to_page ((void *)(uintptr_t )paddr);return NULL ;
Quoted 1 line
}
Thanks Arnd, makes complete sense.
From: Arnd Bergmann
Quoted 13 lines
Sent: 15 December 2022 17:04
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [- Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^
Quoted 7 lines
Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
I hope that doesn't mean it is relying on user space only giving it back valid values?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 13 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.
Quoted 7 lines
It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
Fixes 0d1b756acf60 ("RDMA/siw: Pass a pointer to virt_to_page()")Signed-off-by Arnd Bergmann <[email protected]>
This driver is a big confusion for me too.
Yours,
Linus Walleij
Quoted 17 lines · David Laight
From: Arnd Bergmann
Quoted 16 lines
Sent: 15 December 2022 17:04
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [- Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.
Quoted 7 lines
Quoted 4 lines
It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
I hope that doesn't mean it is relying on user space only giving it back valid values?
It looks to me like this driver totally trusts userspace.
Yours,
Linus Walleij
Quoted 38 lines
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, 16 December 2022 08:47
To: David Laight <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Bernard Metzler <[email protected]>; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; Arnd Bergmann <[email protected]>; [email protected]; linux- [email protected]
Subject: [EXTERNAL] Re: [PATCH] RDMA/siw: fix pointer cast warningQuoted 10 lines · David Laight
From: Arnd Bergmann
Quoted 9 lines
Sent: 15 December 2022 17:04
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointerfrom integer of different size [-
Quoted 12 lines
Quoted 11 lines
Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
Quoted 5 lines
Quoted 2 lines
I hope that doesn't mean it is relying on user space only giving it back valid values?
It looks to me like this driver totally trusts userspace.
Shame on me. Yes, somehow, an access_ok((void __user *)start, len) is missing! Let me fix that when I am back at my desk. Seems it needs immediate action.
Many thanks for pointing that out!
Bernard.
Quoted 2 lines
Yours,
Linus Walleij
From: Bernard Metzler
Quoted 41 lines
Sent: 16 December 2022 10:01
Quoted 39 lines
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, 16 December 2022 08:47
To: David Laight <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Bernard Metzler <[email protected]>; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; Arnd Bergmann <[email protected]>; [email protected]; linux- [email protected]
Subject: [EXTERNAL] Re: [PATCH] RDMA/siw: fix pointer cast warningQuoted 10 lines · David Laight
From: Arnd Bergmann
Quoted 9 lines
Sent: 15 December 2022 17:04
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointerfrom integer of different size [-
Quoted 14 lines
Quoted 11 lines
Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
I hope that doesn't mean it is relying on user space only giving it back valid values?
Quoted 6 lines
Quoted 2 lines
It looks to me like this driver totally trusts userspace.
Shame on me. Yes, somehow, an
access_ok((void __user *)start, len)is missing! Let me fix that when I am back at my desk. Seems it needs immediate action.
That wasn't the sort of issue I was thinking about.
I was worried that it was putting the addresses of kernel memory into buffers written to userspace and then later reading the addresses back from userspace and accessing them.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 59 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Friday, 16 December 2022 11:23
To: Bernard Metzler <[email protected]>; Linus Walleij <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; Arnd Bergmann <[email protected]>; linux- [email protected]; [email protected]
Subject: [EXTERNAL] RE: Re: [PATCH] RDMA/siw: fix pointer cast warningFrom: Bernard Metzler
Quoted 7 lines
Sent: 16 December 2022 10:01
Quoted 5 lines
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, 16 December 2022 08:47
To: David Laight <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Bernard MetzlerQuoted 9 lines
Quoted 9 lines
Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; Arnd Bergmann <[email protected]>; [email protected]; linux- [email protected]
Subject: [EXTERNAL] Re: [PATCH] RDMA/siw: fix pointer cast warningQuoted 1 line · David Laight
From: Arnd Bergmann
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Sent: 15 December 2022 17:04
From: Arnd Bergmann <[email protected]>
The previous build fix left a remaining issue in configurations with 64-bit
dma_addr_ton 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function'
siw_get_pblpage':Quoted 20 lines
Quoted 19 lines
Quoted 1 line
Quoted 1 line
drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointerfrom integer of different size [-
Quoted 7 lines
Quoted 7 lines
Werror=int-to-pointer-cast]
32 | returnvirt_to_page((void *)paddr);
| ^Use the same double cast here that the driver uses elsewhere to convert between
dma_addr_tand void*.Quoted 7 lines
Quoted 4 lines
It took me a while to figure out why this driver does it like this, as there is no hardware access and it just stores kernel pointers in place of device addresses when communicating with the rdma core and with user space.
I hope that doesn't mean it is relying on user space only giving it back valid values?
It looks to me like this driver totally trusts userspace.
Quoted 9 lines
Quoted 3 lines
Shame on me. Yes, somehow, an
access_ok((void __user *)start, len)is missing! Let me fix that when I am back at my desk. Seems it needs immediate action.That wasn't the sort of issue I was thinking about.
I was worried that it was putting the addresses of kernel memory into buffers written to userspace and then later reading the addresses back from userspace and accessing them.
Oh, no, that is not the case. The address mapping is not accessible from userspace. It is local to the kernel driver only to translate user virtual addresses to kernel pages during transmit/receive of application data. The user only knows about its own VA's it uses in its work requests, and during buffer registration.
BUT, you pointed me to something bad. Checking the users permission to register requested memory with the driver is definitely missing. I was under the wrong impression it would be checked by used pin_user_pages(), but that is not the case. pin_user_pages_fast() does that check, other drivers using it, and it looks like a good fix.
Other rdma drivers, like infiniband/hw/usnic, wich also use pin_user_pages(), may suffer from the same problem. There is no checking of user permissions for the memory being registered from user land.
Thanks very much,
Bernard.
Quoted 6 lines
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)