Skip to contentSkip to conversation

udmabuf: fix a buf size overflow issue during udmabuf creation

PATCH In review Xiaogang.Chen 3 participants 7 messages Mar 21, 2025 – Apr 7, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udmabuf: fix a buf size overflow issue during udmabuf creation

From: Xiaogang Chen <[email protected]>

by casting size_limit_mb to u64 when calculate pglimit.

---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +1 -1
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice *device,
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 5 lines

From: Xiaogang Chen <[email protected]>

by casting size_limit_mb to u64 when calculate pglimit.

If nobody objects I'm going to push that to drm-misc-fixes.

Regards,
Christian.

Quoted 17 lines
---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +1 -1
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice *device,
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
maintainer
#2 lore raw

Hi Christian,

Quoted 10 lines

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 5 lines

From: Xiaogang Chen <[email protected]>

by casting size_limit_mb to u64 when calculate pglimit.

If nobody objects I'm going to push that to drm-misc-fixes.

No objection but I wish the author would have added more details in the commit message particularly the value they have used to trigger the overflow. I guess Xiaogang can still comment here and briefly describe the exact use-case/test-case they are running where they encountered this issue.

Thanks,
Vivek

Quoted 22 lines

Regards,
Christian.

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice

Quoted 9 lines
---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +0 -0
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice

*device,

Quoted 8 lines
drivers/dma-buf/udmabuf.c +1 -1
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
maintainer
#3 lore raw

Am 25.03.25 um 07:23 schrieb Kasireddy, Vivek:

Quoted 7 lines

Hi Christian,

Quoted 5 lines

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 4 lines

From: Xiaogang Chen <[email protected]>

by casting size_limit_mb to u64 when calculate pglimit.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

If nobody objects I'm going to push that to drm-misc-fixes.

No objection but I wish the author would have added more details in the commit message particularly the value they have used to trigger the overflow. I guess Xiaogang can still comment here and briefly describe the exact use-case/test-case they are running where they encountered this issue.

Isn't that obvious? At least it was for me.

As soon as you have a value larger than 4095 the 32bit multiplication overflows, resulting in incorrectly limiting the buffer size.

Regards,
Christian.

Quoted 25 lines

Thanks,
Vivek

Quoted 21 lines

Regards,
Christian.

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice

Quoted 9 lines
---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +0 -0
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice

*device,

Quoted 8 lines
drivers/dma-buf/udmabuf.c +1 -1
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
maintainer
#4 lore raw

Hi Christian,

Quoted 19 lines

Subject: Re: [PATCH] udmabuf: fix a buf size overflow issue during udmabuf creation

Am 25.03.25 um 07:23 schrieb Kasireddy, Vivek:

Quoted 5 lines

Hi Christian,

Quoted 3 lines

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 2 lines

From: Xiaogang Chen <[email protected]>

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

by casting size_limit_mb to u64 when calculate pglimit.

If nobody objects I'm going to push that to drm-misc-fixes.

No objection but I wish the author would have added more details in the

commit

Quoted 1 line

message particularly the value they have used to trigger the overflow. I

guess

Quoted 8 lines
Quoted 1 line

Xiaogang can still comment here and briefly describe the exact use-

case/test-case

Quoted 1 line

they are running where they encountered this issue.

Isn't that obvious? At least it was for me.

As soon as you have a value larger than 4095 the 32bit multiplication overflows, resulting in incorrectly limiting the buffer size.

Right, that part makes sense. I was mostly curious about why or how they were using such a large buffer (use-case details).

Thanks,
Vivek

Quoted 29 lines

Regards,
Christian.

Quoted 25 lines

Thanks,
Vivek

Quoted 21 lines

Regards,
Christian.

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice

Quoted 9 lines
---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +0 -0
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice

*device,

Quoted 8 lines
drivers/dma-buf/udmabuf.c +1 -1
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
maintainer
#5 lore raw

Am 26.03.25 um 03:59 schrieb Kasireddy, Vivek:

Quoted 22 lines

Hi Christian,

Quoted 20 lines

Subject: Re: [PATCH] udmabuf: fix a buf size overflow issue during udmabuf creation

Am 25.03.25 um 07:23 schrieb Kasireddy, Vivek:

Quoted 5 lines

Hi Christian,

Quoted 3 lines

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 2 lines

From: Xiaogang Chen <[email protected]>

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

by casting size_limit_mb to u64 when calculate pglimit.

If nobody objects I'm going to push that to drm-misc-fixes.

No objection but I wish the author would have added more details in the

commit

Quoted 1 line

message particularly the value they have used to trigger the overflow. I

guess

Quoted 1 line

Xiaogang can still comment here and briefly describe the exact use-

Quoted 8 lines
Quoted 6 lines

case/test-case

Quoted 1 line

they are running where they encountered this issue.

Isn't that obvious? At least it was for me.

As soon as you have a value larger than 4095 the 32bit multiplication overflows, resulting in incorrectly limiting the buffer size.

Right, that part makes sense. I was mostly curious about why or how they were using such a large buffer (use-case details).

Well I suggested that we use udmabuf to implement shareable dma-bufs which can be allocated from a specific NUMA node and are also accounted in memcg.

But to be honest I have absolutely no idea what's the use case for a buffer larger than 4GiB.

Regards,
Christian.

Quoted 32 lines

Thanks,
Vivek

Quoted 27 lines

Regards,
Christian.

Quoted 24 lines

Thanks,
Vivek

Quoted 21 lines

Regards,
Christian.

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice

Quoted 9 lines
---
 drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +0 -0
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice

*device,

Quoted 8 lines
drivers/dma-buf/udmabuf.c +1 -1
 	if (!ubuf)
 		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
 	for (i = 0; i < head->count; i++) {
 		pgoff_t subpgcnt;
 
#6 lore raw
Quoted 29 lines · Christian König

Am 26.03.25 um 03:59 schrieb Kasireddy, Vivek:

Quoted 28 lines

Hi Christian,

Quoted 26 lines

Subject: Re: [PATCH] udmabuf: fix a buf size overflow issue during udmabuf creation

Am 25.03.25 um 07:23 schrieb Kasireddy, Vivek:

Quoted 5 lines

Hi Christian,

Quoted 3 lines

Am 21.03.25 um 17:41 schrieb Xiaogang.Chen:

Quoted 2 lines

From: Xiaogang Chen<[email protected]>

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

by casting size_limit_mb to u64 when calculate pglimit.

If nobody objects I'm going to push that to drm-misc-fixes.

No objection but I wish the author would have added more details in the

commit

Quoted 1 line

message particularly the value they have used to trigger the overflow. I

guess

Quoted 1 line

Xiaogang can still comment here and briefly describe the exact use-

case/test-case

Quoted 1 line

they are running where they encountered this issue.

Isn't that obvious? At least it was for me.

As soon as you have a value larger than 4095 the 32bit multiplication overflows, resulting in incorrectly limiting the buffer size.

Quoted 8 lines
Quoted 2 lines

Right, that part makes sense. I was mostly curious about why or how they were using such a large buffer (use-case details).

Well I suggested that we use udmabuf to implement shareable dma-bufs which can be allocated from a specific NUMA node and are also accounted in memcg.

But to be honest I have absolutely no idea what's the use case for a buffer larger than 4GiB.

Regards,
Christian.

Sorry, just noticed this email response.

Application may allocate buf bigger than 4GB and map to GPU VM where shadder code uses the buffer.

 Regards

Xiaogang

Quoted 32 lines
Quoted 32 lines

Thanks,
Vivek

Quoted 27 lines

Regards,
Christian.

Quoted 24 lines

Thanks,
Vivek

Quoted 21 lines

Regards,
Christian.

drivers/dma-buf/udmabuf.c static long udmabuf_create(struct miscdevice

Quoted 9 lines
---
  drivers/dma-buf/udmabuf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +0 -0
index 8ce1f074c2d3..e99e3a65a470 100644
@@ -398,7 +398,7 @@ static long udmabuf_create(struct miscdevice

*device,

Quoted 8 lines
drivers/dma-buf/udmabuf.c +1 -1
  	if (!ubuf)
  		return -ENOMEM;
 
-	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
+	pglimit = ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
  	for (i = 0; i < head->count; i++) {
  		pgoff_t subpgcnt;