From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35AE3C4708D for ; Mon, 12 Dec 2022 13:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233131AbiLLN5O (ORCPT ); Mon, 12 Dec 2022 08:57:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233148AbiLLN4k (ORCPT ); Mon, 12 Dec 2022 08:56:40 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADECC15735 for ; Mon, 12 Dec 2022 05:56:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id E2C87CE0F1B for ; Mon, 12 Dec 2022 13:56:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A079AC433D2; Mon, 12 Dec 2022 13:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670853395; bh=KSUA4w4D8iVRFHCvRuAbwbHEXE09wLHrZQ8gcCDa8bM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KHCmhedMU6e+EIv4lk0B1AQRTMB5BtkA8gLCOHn3qUo6AwaRchN4bK1fbbX854hSX 1NqbAALF3PG7o5VqyYk3Zi56Adq96WyfG5TvUO3eWzSQM8nvBNgA0Ncno4qsDfUM51 G32lmnZqYgXkg0SLCR70u8Ou16ysZpgR3w0+SNIs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anastasia Belova , Jiri Kosina Subject: [PATCH 4.9 13/31] HID: hid-lg4ff: Add check for empty lbuf Date: Mon, 12 Dec 2022 14:19:31 +0100 Message-Id: <20221212130910.706339581@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212130909.943483205@linuxfoundation.org> References: <20221212130909.943483205@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Anastasia Belova commit d180b6496143cd360c5d5f58ae4b9a8229c1f344 upstream. If an empty buf is received, lbuf is also empty. So lbuf is accessed by index -1. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: f31a2de3fe36 ("HID: hid-lg4ff: Allow switching of Logitech gaming wheels between compatibility modes") Signed-off-by: Anastasia Belova Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-lg4ff.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -880,6 +880,12 @@ static ssize_t lg4ff_alternate_modes_sto return -ENOMEM; i = strlen(lbuf); + + if (i == 0) { + kfree(lbuf); + return -EINVAL; + } + if (lbuf[i-1] == '\n') { if (i == 1) { kfree(lbuf);