From patchwork Sun Aug 23 19:40:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 1350004 X-Patchwork-Delegate: mkubecek@suse.cz Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BZQb12Xp4z9sR4 for ; Mon, 24 Aug 2020 05:40:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbgHWTk1 (ORCPT ); Sun, 23 Aug 2020 15:40:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:50694 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgHWTkZ (ORCPT ); Sun, 23 Aug 2020 15:40:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C2E07AECB; Sun, 23 Aug 2020 19:40:53 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 27ECE6030D; Sun, 23 Aug 2020 21:40:24 +0200 (CEST) Message-Id: <48ef048e78abee08eb6403985786659840d419e4.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 3/9] ioctl: prevent argc underflow in do_perqueue() To: netdev@vger.kernel.org Cc: Andrew Lunn , Nicholas Nunley Date: Sun, 23 Aug 2020 21:40:24 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When first command line argument after "-Q" is "queue_mask", we parse the queue mask and following subcommand without checking if these arguments do actually exist. Add check if we have at least two arguments left after "queue_mask" in the corresponding branch. Fixes: 9ecd54248b1a ("ethtool: introduce new ioctl for per-queue settings") Signed-off-by: Michal Kubecek --- ethtool.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ethtool.c b/ethtool.c index 4fa7a2c1716f..6c12452be7b4 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5880,6 +5880,8 @@ static int do_perqueue(struct cmd_context *ctx) "The sub commands will be applied to all %d queues\n", n_queues); } else { + if (ctx->argc <= 2) + exit_bad_args(); ctx->argc--; ctx->argp++; if (parse_hex_u32_bitmap(*ctx->argp, MAX_NUM_QUEUE,