linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Andrej Shadura <andrew.shadura@collabora.co.uk>
Cc: "Jiří Kosina" <jikos@kernel.org>,
	linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
	stable@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH v2 1/2] HID: u2fzero: explicitly check for errors
Date: Mon, 18 Oct 2021 10:15:27 -0400	[thread overview]
Message-ID: <20211018141527.GA1048431@rowland.harvard.edu> (raw)
In-Reply-To: <20211018122144.25131-1-andrew.shadura@collabora.co.uk>

On Mon, Oct 18, 2021 at 02:21:43PM +0200, Andrej Shadura wrote:
> The previous commit fixed handling of incomplete packets but broke error
> handling: offsetof returns an unsigned value (size_t), but when compared
> against the signed return value, the return value is interpreted as if
> it were unsigned, so negative return values are never less than the
> offset.
> 
> Fixes: 22d65765f211 ("HID: u2fzero: ignore incomplete packets without data")
> Fixes: 42337b9d4d95 ("HID: add driver for U2F Zero built-in LED and RNG")
> Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
> ---
>  drivers/hid/hid-u2fzero.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-u2fzero.c b/drivers/hid/hid-u2fzero.c
> index d70cd3d7f583..5145d758bea0 100644
> --- a/drivers/hid/hid-u2fzero.c
> +++ b/drivers/hid/hid-u2fzero.c
> @@ -200,7 +200,7 @@ static int u2fzero_rng_read(struct hwrng *rng, void *data,
>  	ret = u2fzero_recv(dev, &req, &resp);
>  
>  	/* ignore errors or packets without data */
> -	if (ret < offsetof(struct u2f_hid_msg, init.data))
> +	if (ret < 0 || ret < offsetof(struct u2f_hid_msg, init.data))

Although the patch description does a good job of explaining what's 
happening, someone merely reading the code will most likely not 
understand.

One alternative is to add a comment.  Another is simply to force a 
signed integer comparison:

	if (ret < (ssize_t) offsetof(...

Alan Stern

  parent reply	other threads:[~2021-10-18 14:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18 12:21 [PATCH v2 1/2] HID: u2fzero: explicitly check for errors Andrej Shadura
2021-10-18 12:21 ` [PATCH v2 2/2] HID: u2fzero: properly handle timeouts in usb_submit_urb Andrej Shadura
2021-10-18 14:15 ` Alan Stern [this message]
2021-10-18 14:17   ` [PATCH v2 1/2] HID: u2fzero: explicitly check for errors Andrej Shadura
2021-10-18 14:38     ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211018141527.GA1048431@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=andrew.shadura@collabora.co.uk \
    --cc=jikos@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).