linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource()
@ 2022-11-26  5:07 Harshit Mogalapalli
  2022-12-02  8:55 ` Juergen Gross
  0 siblings, 1 reply; 2+ messages in thread
From: Harshit Mogalapalli @ 2022-11-26  5:07 UTC (permalink / raw)
  Cc: harshit.m.mogalapalli, error27, harshit.m.mogalapalli,
	Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
	Paul Durrant, Boris Ostrovsky, xen-devel, linux-kernel

As 'kdata.num' is user-controlled data, if user tries to allocate
memory larger than(>=) MAX_ORDER, then kcalloc() will fail, it
creates a stack trace and messes up dmesg with a warning.

Call trace:
-> privcmd_ioctl
--> privcmd_ioctl_mmap_resource

Add __GFP_NOWARN in order to avoid too large allocation warning.
This is detected by static analysis using smatch.

Fixes: 3ad0876554ca ("xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 drivers/xen/privcmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index fae50a24630b..1edf45ee9890 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -760,7 +760,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
 		goto out;
 	}
 
-	pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL);
+	pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL | __GFP_NOWARN);
 	if (!pfns) {
 		rc = -ENOMEM;
 		goto out;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource()
  2022-11-26  5:07 [PATCH] xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource() Harshit Mogalapalli
@ 2022-12-02  8:55 ` Juergen Gross
  0 siblings, 0 replies; 2+ messages in thread
From: Juergen Gross @ 2022-12-02  8:55 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: error27, harshit.m.mogalapalli, Stefano Stabellini,
	Oleksandr Tyshchenko, Paul Durrant, Boris Ostrovsky, xen-devel,
	linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 652 bytes --]

On 26.11.22 06:07, Harshit Mogalapalli wrote:
> As 'kdata.num' is user-controlled data, if user tries to allocate
> memory larger than(>=) MAX_ORDER, then kcalloc() will fail, it
> creates a stack trace and messes up dmesg with a warning.
> 
> Call trace:
> -> privcmd_ioctl
> --> privcmd_ioctl_mmap_resource
> 
> Add __GFP_NOWARN in order to avoid too large allocation warning.
> This is detected by static analysis using smatch.
> 
> Fixes: 3ad0876554ca ("xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-02  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26  5:07 [PATCH] xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource() Harshit Mogalapalli
2022-12-02  8:55 ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).