From patchwork Mon Oct 18 06:47:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 12565187 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B068DC433EF for ; Mon, 18 Oct 2021 06:48:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DE9660F22 for ; Mon, 18 Oct 2021 06:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbhJRGuR (ORCPT ); Mon, 18 Oct 2021 02:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbhJRGuR (ORCPT ); Mon, 18 Oct 2021 02:50:17 -0400 Received: from cambridge.shadura.me (cambridge.shadura.me [IPv6:2a00:1098:0:86:1000:13:0:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C885C06161C; Sun, 17 Oct 2021 23:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=shadura.me; s=a; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To: From:Content-Type:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References; bh=DKSw4okpW6/D0kp2xm5+q84mhGCaMFDuHCe67MAT7GE=; b=gxIeV/9mHqzl0G /DWNq+YfjlqAkl0mMidihuvDHNAuRZMSKXLoq1WcMGetl+yK+gldtoPr+Q3d2+c41szsLwNsu8iJo VUVgXtfb+DDz5pElPf/Nt0wSRuKIlWI6O02it6VRWiDfSM5/DvaeJ9gClwHAvJJFsCA41Ah9TvGc+ pNg=; Received: from 178-143-43-60.dynamic.orange.sk ([178.143.43.60] helo=localhost) by cambridge.shadura.me with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mcMRG-0001cA-R0; Mon, 18 Oct 2021 08:48:02 +0200 From: Andrej Shadura To: =?utf-8?b?SmnFmcOtIEtvc2luYQ==?= Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org, kernel@collabora.com, Benjamin Tissoires Subject: [PATCH 1/2] HID: u2fzero: explicitly check for errors Date: Mon, 18 Oct 2021 08:47:59 +0200 Message-Id: <20211018064800.15173-1-andrew.shadura@collabora.co.uk> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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: 22d65765f211c("HID: u2fzero: ignore incomplete packets without data") Fixes: 42337b9d4d958("HID: add driver for U2F Zero built-in LED and RNG") Signed-off-by: Andrej Shadura --- 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)) return 0; /* only take the minimum amount of data it is safe to take */