kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: prevent a ternary sign expansion bug
@ 2021-04-22  9:00 Dan Carpenter
  2021-04-22 11:03 ` Felipe Balbi
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-04-22  9:00 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Greg Kroah-Hartman, Alan Stern, Jens Axboe, Felix Kuehling,
	Andrew Morton, Gustavo A. R. Silva, Masahiro Yamada,
	Zhang Qilong, linux-usb, linux-kernel, kernel-janitors

The problem is that "req->actual" is a u32, "req->status" is an int, and
iocb->ki_complete() takes a long.  We would expect that a negative error
code in "req->status" would translate to a negative long value.

But what actually happens is that because "req->actual" is a u32, the
error codes is type promoted to a high positive value and then remains
a positive value when it is cast to long.  (No sign expansion).

We can fix this by casting "req->status" to long.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/usb/gadget/legacy/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 71e7d10dd76b..cd8e2737947b 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -498,7 +498,8 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
 		iocb->private = NULL;
 		/* aio_complete() reports bytes-transferred _and_ faults */
 
-		iocb->ki_complete(iocb, req->actual ? req->actual : req->status,
+		iocb->ki_complete(iocb,
+				req->actual ? req->actual : (long)req->status,
 				req->status);
 	} else {
 		/* ep_copy_to_user() won't report both; we hide some faults */
-- 
2.30.2


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

* Re: [PATCH] usb: gadget: prevent a ternary sign expansion bug
  2021-04-22  9:00 [PATCH] usb: gadget: prevent a ternary sign expansion bug Dan Carpenter
@ 2021-04-22 11:03 ` Felipe Balbi
  0 siblings, 0 replies; 2+ messages in thread
From: Felipe Balbi @ 2021-04-22 11:03 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Greg Kroah-Hartman, Alan Stern, Jens Axboe, Felix Kuehling,
	Andrew Morton, Gustavo A. R. Silva, Masahiro Yamada,
	Zhang Qilong, linux-usb, linux-kernel, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

Dan Carpenter <dan.carpenter@oracle.com> writes:

> The problem is that "req->actual" is a u32, "req->status" is an int, and
> iocb->ki_complete() takes a long.  We would expect that a negative error
> code in "req->status" would translate to a negative long value.
>
> But what actually happens is that because "req->actual" is a u32, the
> error codes is type promoted to a high positive value and then remains
> a positive value when it is cast to long.  (No sign expansion).
>
> We can fix this by casting "req->status" to long.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

I'm just going to assume your type promotion rank is correct :-)

Acked-by: Felipe Balbi <balbi@kernel.org>

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 857 bytes --]

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

end of thread, other threads:[~2021-04-22 11:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22  9:00 [PATCH] usb: gadget: prevent a ternary sign expansion bug Dan Carpenter
2021-04-22 11:03 ` Felipe Balbi

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).