From patchwork Mon Apr 22 12:37:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1926176 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=POa3rXdc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VNPt742Npz1yZP for ; Mon, 22 Apr 2024 22:38:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id D394C81E77; Mon, 22 Apr 2024 12:38:04 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6GeTZZXcg1iZ; Mon, 22 Apr 2024 12:38:04 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org DACCB81BC2 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=POa3rXdc Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id DACCB81BC2; Mon, 22 Apr 2024 12:38:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AA8A7C007C; Mon, 22 Apr 2024 12:38:03 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 91E80C0037 for ; Mon, 22 Apr 2024 12:38:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 6B18281BC2 for ; Mon, 22 Apr 2024 12:38:02 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vYBzNKvBlTiL for ; Mon, 22 Apr 2024 12:38:01 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=pvalerio@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 1774181975 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1774181975 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1774181975 for ; Mon, 22 Apr 2024 12:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713789479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J1GjsRcN0fpjOyWKPyg9ZrdWb3nlflQBs8IUqnyhRFg=; b=POa3rXdcdXidbxwSYbmkmXX6ssdRgRlbVUrYqm8kJ+zG1sjU3eBqaDNT6guG5zYUWP9fVE 7etafWdTmZEPmGX+u2l/f3hO1Zriirt2GvvqBIWutl1IPknoampJaTbd4Qm+FBAtTC+YQ8 sIh2FqJaxaJWZ8xOW9w0HfKUqbpk6c0= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-9F1iju7aOlmqUNlHswelJw-1; Mon, 22 Apr 2024 08:37:58 -0400 X-MC-Unique: 9F1iju7aOlmqUNlHswelJw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57059563f08so531092a12.2 for ; Mon, 22 Apr 2024 05:37:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713789476; x=1714394276; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J1GjsRcN0fpjOyWKPyg9ZrdWb3nlflQBs8IUqnyhRFg=; b=QMqRUy6R3Jsdr23z9F8aGnj+B+YS4DXhkwg/UhGWO1bikfR30wy67GFOc54fwJfcuy MJh0cLrEXvGwnHQQfLpeEOBUwgbsob10m3DyrDHebtLH8GLvm79RQ/RBc8jcsFeI02QS +RJ8yPiBgbI+F5H41ApYnj5w1juRLAHCxq4Ys8sNM6t1jYlfqMVd/65mMbAuSoYwzcwC 04Bm0tS2VAqot5DzXRzXDxSWCAeMzqhPaUuOP4r9YFM19hRYk50McEJTu7ylkoFVdPoq GkeP90LEKCzlAlu16fRAxhwt4lT2BNWPom5bzSPMMLYJtSHQs2kFRheFhPxFtLCkJYsO Q4ag== X-Gm-Message-State: AOJu0YwiGAaS+VqJEend2KxNbUbXegxU3XMASd6LUVVpL7EU6KG0Uu5T 1H0bguCmN0zKLS2OLgrdx9Nj964vb41Qyo18VsOjklGtsnLiumQ9a6T/C2S/IENeQXvB9ohI9ui 2z9uSJKcA5R7cC3EJckmecjfbSM/Sc9AIfAHQNhclVJqATjC3lDtAD/oe8dA+yCX2a/cmUkIirA eg7UR1+cCvisS1Koq2HJt9o/geKdUvbmB+eaanqBs= X-Received: by 2002:a50:9f83:0:b0:56f:ec04:b4f9 with SMTP id c3-20020a509f83000000b0056fec04b4f9mr5114791edf.1.1713789476360; Mon, 22 Apr 2024 05:37:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErax4OfmmDtHgKnvDOmHWyF4sGFnmjtkHX27z/hfYgSyFm2hJXmVYqEM+nKPYn7rC6inu5Mw== X-Received: by 2002:a50:9f83:0:b0:56f:ec04:b4f9 with SMTP id c3-20020a509f83000000b0056fec04b4f9mr5114773edf.1.1713789475869; Mon, 22 Apr 2024 05:37:55 -0700 (PDT) Received: from localhost (net-2-35-80-241.cust.vodafonedsl.it. [2.35.80.241]) by smtp.gmail.com with ESMTPSA id i8-20020aa7c9c8000000b00571c1df911fsm4990262edt.37.2024.04.22.05.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 05:37:55 -0700 (PDT) From: Paolo Valerio To: ovs-dev@openvswitch.org Date: Mon, 22 Apr 2024 14:37:41 +0200 Message-ID: <20240422123742.1324328-1-pvalerio@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH] dpctl: fix segfault on ct-{set,del}-limits X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When no parameters other than the datapath are specified a segfault occurs. Fix it by checking the argument access is inside the bounds. Signed-off-by: Paolo Valerio Acked-by: Simon Horman Acked-by: Kevin Traynor --- lib/dpctl.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/dpctl.c b/lib/dpctl.c index 34ee7d0e2..3c555a559 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -2168,13 +2168,20 @@ static int dpctl_ct_set_limits(int argc, const char *argv[], struct dpctl_params *dpctl_p) { - struct dpif *dpif; - struct ds ds = DS_EMPTY_INITIALIZER; + struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits); int i = dp_arg_exists(argc, argv) ? 2 : 1; + struct ds ds = DS_EMPTY_INITIALIZER; + struct dpif *dpif = NULL; uint32_t default_limit; - struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits); + int error; + + if (i >= argc) { + ds_put_cstr(&ds, "too few arguments"); + error = EINVAL; + goto error; + } - int error = opt_dpif_open(argc, argv, dpctl_p, INT_MAX, &dpif); + error = opt_dpif_open(argc, argv, dpctl_p, INT_MAX, &dpif); if (error) { return error; } @@ -2261,11 +2268,17 @@ static int dpctl_ct_del_limits(int argc, const char *argv[], struct dpctl_params *dpctl_p) { - struct dpif *dpif; + struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits); + int i = dp_arg_exists(argc, argv) ? 2 : 1; struct ds ds = DS_EMPTY_INITIALIZER; + struct dpif *dpif = NULL; int error; - int i = dp_arg_exists(argc, argv) ? 2 : 1; - struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits); + + if (i >= argc) { + ds_put_cstr(&ds, "too few arguments"); + error = EINVAL; + goto error; + } error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif); if (error) {