From patchwork Tue Sep 29 11:00:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 262927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC7A8C47423 for ; Tue, 29 Sep 2020 12:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F8E52075F for ; Tue, 29 Sep 2020 12:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601383071; bh=ZTL5jCG7jOOIjWhvX+LYQwkt2VOk6APcn1Oums1GkMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qZ4RzlPzwlOFpJZc4vBrszOeKMw9bZWolfHbDU2T19Xu/mckcBxlIf7iAegKlJRHl iO6YI/Z0aoxavZlWYJxw0c63fbyPgzNJ6/OiavNXQV2xN/nbiZlbJHbXSZR7uhztf4 yd3NZntCTXSXs8mfJVznXPjs0disJOo6s+eMUB4U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730615AbgI2Mhi (ORCPT ); Tue, 29 Sep 2020 08:37:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:35542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729068AbgI2LR6 (ORCPT ); Tue, 29 Sep 2020 07:17:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E637B21D7D; Tue, 29 Sep 2020 11:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378271; bh=ZTL5jCG7jOOIjWhvX+LYQwkt2VOk6APcn1Oums1GkMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ht8299NDG6xff4nocRlEmPzWyHVtx4K6YWzaGPMjh18uaEAbi8JTAVUt5TwXtFPfC obaaR55SkGOYqpVuL5L8la7wPODSxA1dJQY/rkHU0agJhA3v/5UOaQGtkU3Kp2If1i OlfbYGBx5o4qLHnwZOxi+6a469WmIMjINYwzo3XU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gabriel Ravier , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 4.14 091/166] tools: gpio-hammer: Avoid potential overflow in main Date: Tue, 29 Sep 2020 13:00:03 +0200 Message-Id: <20200929105939.761389534@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gabriel Ravier [ Upstream commit d1ee7e1f5c9191afb69ce46cc7752e4257340a31 ] If '-o' was used more than 64 times in a single invocation of gpio-hammer, this could lead to an overflow of the 'lines' array. This commit fixes this by avoiding the overflow and giving a proper diagnostic back to the user Signed-off-by: Gabriel Ravier Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- tools/gpio/gpio-hammer.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/gpio/gpio-hammer.c b/tools/gpio/gpio-hammer.c index 4bcb234c0fcab..3da5462a0c7d3 100644 --- a/tools/gpio/gpio-hammer.c +++ b/tools/gpio/gpio-hammer.c @@ -138,7 +138,14 @@ int main(int argc, char **argv) device_name = optarg; break; case 'o': - lines[i] = strtoul(optarg, NULL, 10); + /* + * Avoid overflow. Do not immediately error, we want to + * be able to accurately report on the amount of times + * '-o' was given to give an accurate error message + */ + if (i < GPIOHANDLES_MAX) + lines[i] = strtoul(optarg, NULL, 10); + i++; break; case '?': @@ -146,6 +153,14 @@ int main(int argc, char **argv) return -1; } } + + if (i >= GPIOHANDLES_MAX) { + fprintf(stderr, + "Only %d occurences of '-o' are allowed, %d were found\n", + GPIOHANDLES_MAX, i + 1); + return -1; + } + nlines = i; if (!device_name || !nlines) {