Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1543753iol; Fri, 10 Jun 2022 09:33:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4l4YS3NhgwN7dy3L6aYc+Mr7dDpjZSGp105jbLm/CPlXZg2LhG+xmhJYssKj4XI8j9mAD X-Received: by 2002:a05:6402:3490:b0:42f:b592:f364 with SMTP id v16-20020a056402349000b0042fb592f364mr40474607edc.66.1654878816789; Fri, 10 Jun 2022 09:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654878816; cv=none; d=google.com; s=arc-20160816; b=OIzkJbZz7t7WsFM8r4Rn0Cz+kA4b9pJSQKeGXE502Cpc2uoOHyHkM2oyPLOV149nzm Ck5HwCG+IeebqWJzhbPLhmiUwqpiMoSWkLqyA+qYr8r0et+KjiWVwJ6HTdnKNtQVxGCj zIC08wwlGMgOyUrApuDEZXXDNmLtQQ+vG2KAU+4hz+y0RzWqENZk8lalyg2Fd7ZypT9y v/3Q1NKqrlM3fN+gLYJL+ZT156BRE4eIaQBzeoBpoVaDZI+ufY8OOeVlnzOE37jyJk79 lMSHgYEMURJ6WT0WeDhdJM46J7TK8y0KmWP418XMGXv823w7t6DdrGUCFLS6lsWVU76j 9xpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=43meA/r92kh0CxM1YdpORf+ubVh2S9/XYnxfpi31kfI=; b=hgwC39FcmLl0IQheuUniILqSopm3ljlzNMVj4tOva2aOwqukc0SYPvLT4Wt81i69+o TB0hSy21psNz/6II4xS7Ty7gkE9aE8HUigf//f1kg8BStUlukOx2li2xT8jh9SAO+5Bn OoTBhDvICXBjlR9E7zcQeO4joPC0o1l3+CbkEAH7i0C4ER3MfV/bX6SoZHf/J6Cjv37K Ch8dJnNl4OGG5k1yMcdirtMLynCytXJ0Ir7JKLLEXw/4Jr0XPoPwSwZ1qWCQlKKejkw8 L/WqTJI7BXE1+eAq9tqQZ/15WkSTCijcqWoqn2zUUz4MYR1Frd8eXc99Th9VYx56as47 QIgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y7aJA8Yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg4-20020a1709072cc400b0070bb971358csi23436960ejc.195.2022.06.10.09.33.10; Fri, 10 Jun 2022 09:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y7aJA8Yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345481AbiFJPqf (ORCPT + 99 others); Fri, 10 Jun 2022 11:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344073AbiFJPqW (ORCPT ); Fri, 10 Jun 2022 11:46:22 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E636C3B3F5 for ; Fri, 10 Jun 2022 08:46:20 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id z11so2395978ilq.6 for ; Fri, 10 Jun 2022 08:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=43meA/r92kh0CxM1YdpORf+ubVh2S9/XYnxfpi31kfI=; b=Y7aJA8Yu5+r6p/HHzNqOJL2V6fzXWk433pPrrfOP6oOLjCkTIMnXJ5AChT/9UT1HOB hkVgzRT3Fe8YfVrBEVygkxI7UDvNGymbaEtTR7/V3y5rczFrZQmiT4K4mJ5/RDW3m8uI Q5pQvJewBcYF88lskqYgToICp+wx+BbyEi0T7Tyrk+5SAi0HsmEQLm/qZh0b3EfB/mha MXaL5WhWWEYe/FQkeVQ+kCR2LJ0abETtBTyN6yrImyztuGRev2bYgRmYounZKVteEV8P EZDPjL2xpLyrIwY8o9FcwKy4giVzyyaeRQIkrG0gZyBgJN7OERBdpFGpOLOAmXDCBJGw SNzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=43meA/r92kh0CxM1YdpORf+ubVh2S9/XYnxfpi31kfI=; b=aP+oxGOG8fHDIu6aP2mwfRTrB5DsO8lMEXopTMNcY2VB+RuUDfEJWD+LRXQLw1aMFq 4PqseMwc0O/K2drZ0r7OTjonkioTiKbZxh3uTNlQ9SfzEC7R/sVhsBsgIPmMsgA9/baT j/tadCnjvJFtpXHmsHU+xhYOmlFAtyvADWIy9X4igr2rpwaTPLGJH0sn4qmZbq/6iGZQ +rdeJaR7mZVEYAoOyyu5ejkXEaB6GFG9nH6Z9PXCOEU65jdMeO6VpyYSVcBzW1DEDesN /WM6Y9TqrCIB+TQjprh7NXy4PHqRuehpe5p+YVw3fdfS0S7Rulu1E3incs1oVJhj0RWk yCdw== X-Gm-Message-State: AOAM530Ru89QHLJZDaFc7dD3v7LH+V1rJcZw4GpL6CB1/caBm+aWTHTr PwvxE/5hIxsud9urq91i5IEzVA== X-Received: by 2002:a05:6e02:f44:b0:2d3:b54f:d83e with SMTP id y4-20020a056e020f4400b002d3b54fd83emr24924981ilj.9.1654875980181; Fri, 10 Jun 2022 08:46:20 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id y15-20020a92950f000000b002d3adf71893sm12100488ilh.20.2022.06.10.08.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 08:46:19 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/6] net: ipa: verify command channel TLV count Date: Fri, 10 Jun 2022 10:46:10 -0500 Message-Id: <20220610154616.249304-2-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220610154616.249304-1-elder@linaro.org> References: <20220610154616.249304-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In commit 8797972afff3d ("net: ipa: remove command info pool"), the maximum number of IPA commands that would be sent in a single transaction was defined. That number can't exceed the size of the TLV FIFO on the command channel, and we can check that at runtime. To add this check, pass a new flag to gsi_channel_data_valid() to indicate the channel being checked is being used for IPA commands. Knowing that we can also verify the channel direction is correct. Use a new local variable that refers to the command-specific portion of the data being checked. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 9cfe84319ee4d..65ed5a697577e 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -2001,9 +2001,10 @@ static void gsi_channel_evt_ring_exit(struct gsi_channel *channel) gsi_evt_ring_id_free(gsi, evt_ring_id); } -static bool gsi_channel_data_valid(struct gsi *gsi, +static bool gsi_channel_data_valid(struct gsi *gsi, bool command, const struct ipa_gsi_endpoint_data *data) { + const struct gsi_channel_data *channel_data; u32 channel_id = data->channel_id; struct device *dev = gsi->dev; @@ -2019,10 +2020,24 @@ static bool gsi_channel_data_valid(struct gsi *gsi, return false; } - if (!data->channel.tlv_count || - data->channel.tlv_count > GSI_TLV_MAX) { + if (command && !data->toward_ipa) { + dev_err(dev, "command channel %u is not TX\n", channel_id); + return false; + } + + channel_data = &data->channel; + + if (!channel_data->tlv_count || + channel_data->tlv_count > GSI_TLV_MAX) { dev_err(dev, "channel %u bad tlv_count %u; must be 1..%u\n", - channel_id, data->channel.tlv_count, GSI_TLV_MAX); + channel_id, channel_data->tlv_count, GSI_TLV_MAX); + return false; + } + + if (command && IPA_COMMAND_TRANS_TRE_MAX > channel_data->tlv_count) { + dev_err(dev, "command TRE max too big for channel %u (%u > %u)\n", + channel_id, IPA_COMMAND_TRANS_TRE_MAX, + channel_data->tlv_count); return false; } @@ -2031,22 +2046,22 @@ static bool gsi_channel_data_valid(struct gsi *gsi, * gsi_channel_tre_max() is computed, tre_count has to be almost * twice the TLV FIFO size to satisfy this requirement. */ - if (data->channel.tre_count < 2 * data->channel.tlv_count - 1) { + if (channel_data->tre_count < 2 * channel_data->tlv_count - 1) { dev_err(dev, "channel %u TLV count %u exceeds TRE count %u\n", - channel_id, data->channel.tlv_count, - data->channel.tre_count); + channel_id, channel_data->tlv_count, + channel_data->tre_count); return false; } - if (!is_power_of_2(data->channel.tre_count)) { + if (!is_power_of_2(channel_data->tre_count)) { dev_err(dev, "channel %u bad tre_count %u; not power of 2\n", - channel_id, data->channel.tre_count); + channel_id, channel_data->tre_count); return false; } - if (!is_power_of_2(data->channel.event_count)) { + if (!is_power_of_2(channel_data->event_count)) { dev_err(dev, "channel %u bad event_count %u; not power of 2\n", - channel_id, data->channel.event_count); + channel_id, channel_data->event_count); return false; } @@ -2062,7 +2077,7 @@ static int gsi_channel_init_one(struct gsi *gsi, u32 tre_count; int ret; - if (!gsi_channel_data_valid(gsi, data)) + if (!gsi_channel_data_valid(gsi, command, data)) return -EINVAL; /* Worst case we need an event for every outstanding TRE */ -- 2.34.1