From patchwork Thu Sep 16 15:59:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 513028 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1429557jao; Thu, 16 Sep 2021 10:26:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSCrAo7ftZw1YtsN82iMmjZgwadMV4+ZfC+lT6vj0sWOu9Bzo7bLcNhAMd/nUErahR/QQT X-Received: by 2002:a50:d80f:: with SMTP id o15mr7759260edj.52.1631813205141; Thu, 16 Sep 2021 10:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631813205; cv=none; d=google.com; s=arc-20160816; b=akSIuR74XXfsCqlXcb9CXnTqvZQ/9IFNJURv5SEjCF45aW5ifPdrylxRN1sTdMTNlz 7RVdQiwT6V7vrGnIXmkU57Rd7k4PhQuJLdw71q3YaQTcV4doAopUoBK8I7fkL3Ej8DvU 7kpyOq1njvdD0+N54wrs632Vb1IsLZl2md8hkT/we8/m3P8CLV/JV71xpN7TfbQ7vwu1 dj4Ju9vmDTFUCZYKyl7hzIjs5AepPHAWNQhwm4GIi0MCia9NJShBMZNfWTjYOD7rE6oC 7lC4Tn04gSz1pSeZIsbLmdjk8Q4b5qidOYufLVYMG7px9H6mJDodu7wPspQkJZ0pGzh2 6bmw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9CzfVvUgE943WPE5ftkl88X4fT40cnbHFedjsCKESJU=; b=BpajBDGTtKmJQg2FgwBuQ8JU8g3UB+GtmO5WlHg/SpRDhZGuTSSqNAOT32AAUbNiJP B5qUexSefPVyjdXV7F8dU75wQSzsmZmP+kFj/iSmlIAp/l4HfqcTHcpd4+TuuVtrMura J2p1VxftzyfS6alSxu+o3Vl/rCRdl+BF9pV7Qj5tUnxLVpchL33UxnU7Wx7NC9Ayb2ZA cI3HPfdjHIRTLbL+wkOyK7SUoIJFPuWBotpeU/rflft77tGK2cYcz1hoRHbDqcSPnS+t uHNaCL/zxCjQAceQFqxsConFWRiEBd4sGDXZ1gwGztfft1ckvB3wzvWKZ/lh7CBaOl7X rrHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bCtqouMJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ka8si3766293ejb.83.2021.09.16.10.26.44; Thu, 16 Sep 2021 10:26:45 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bCtqouMJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347322AbhIPR2D (ORCPT + 11 others); Thu, 16 Sep 2021 13:28:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:46950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348327AbhIPRZz (ORCPT ); Thu, 16 Sep 2021 13:25:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D10CC630EA; Thu, 16 Sep 2021 16:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810663; bh=uKKv48X/rwTXchpUk/HynlKWdL8cvr6NSDQypKRjBG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bCtqouMJo1hLtOSXHL7D3d/BWn+vLEYngYxpafZWRQDNDz/02JkZkVYLPNd/kYkcB mApKSg+MWSHOQSExP6uU0H/FwjpwetC3yKt8HMWchJJXTjS2DWqDBy9/T13HzF1Ici 14dRdHDQYgOV62Ziky2Vz2UYPD57qjDaFiaMRTQE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Elder , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 223/432] net: ipa: fix ipa_cmd_table_valid() Date: Thu, 16 Sep 2021 17:59:32 +0200 Message-Id: <20210916155818.406946877@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Alex Elder [ Upstream commit f2c1dac0abcfa93e8b20065b8d6b4b2b6f9990aa ] Stop supporting different sizes for hashed and non-hashed filter or route tables. Add BUILD_BUG_ON() calls to verify the sizes of the fields in the filter/route table initialization immediate command are the same. Add a check to ipa_cmd_table_valid() to ensure the size of the memory region being checked fits within the immediate command field that must hold it. Remove two Boolean parameters used only for error reporting. This actually fixes a bug that would only show up if IPA_VALIDATE were defined. Define ipa_cmd_table_valid() unconditionally (no longer dependent on IPA_VALIDATE). Signed-off-by: Alex Elder Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ipa/ipa_cmd.c | 38 ++++++++++++++++++++++++------------- drivers/net/ipa/ipa_cmd.h | 15 +++------------ drivers/net/ipa/ipa_table.c | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) -- 2.30.2 diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index af44ca41189e..bda8677eae88 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -159,35 +159,45 @@ static void ipa_cmd_validate_build(void) BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); #undef TABLE_COUNT_MAX #undef TABLE_SIZE -} -#ifdef IPA_VALIDATE + /* Hashed and non-hashed fields are assumed to be the same size */ + BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK) != + field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); + BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) != + field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK)); +} /* Validate a memory region holding a table */ -bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, - bool route, bool ipv6, bool hashed) +bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route) { + u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); + u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK); + const char *table = route ? "route" : "filter"; struct device *dev = &ipa->pdev->dev; - u32 offset_max; - offset_max = hashed ? field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) - : field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); + /* Size must fit in the immediate command field that holds it */ + if (mem->size > size_max) { + dev_err(dev, "%s table region size too large\n", table); + dev_err(dev, " (0x%04x > 0x%04x)\n", + mem->size, size_max); + + return false; + } + + /* Offset must fit in the immediate command field that holds it */ if (mem->offset > offset_max || ipa->mem_offset > offset_max - mem->offset) { - dev_err(dev, "IPv%c %s%s table region offset too large\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter"); + dev_err(dev, "%s table region offset too large\n", table); dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", ipa->mem_offset, mem->offset, offset_max); return false; } + /* Entire memory range must fit within IPA-local memory */ if (mem->offset > ipa->mem_size || mem->size > ipa->mem_size - mem->offset) { - dev_err(dev, "IPv%c %s%s table region out of range\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter"); + dev_err(dev, "%s table region out of range\n", table); dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", mem->offset, mem->size, ipa->mem_size); @@ -197,6 +207,8 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, return true; } +#ifdef IPA_VALIDATE + /* Validate the memory region that holds headers */ static bool ipa_cmd_header_valid(struct ipa *ipa) { diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h index b99262281f41..ea723419c826 100644 --- a/drivers/net/ipa/ipa_cmd.h +++ b/drivers/net/ipa/ipa_cmd.h @@ -57,20 +57,18 @@ struct ipa_cmd_info { enum dma_data_direction direction; }; -#ifdef IPA_VALIDATE - /** * ipa_cmd_table_valid() - Validate a memory region holding a table * @ipa: - IPA pointer * @mem: - IPA memory region descriptor * @route: - Whether the region holds a route or filter table - * @ipv6: - Whether the table is for IPv6 or IPv4 - * @hashed: - Whether the table is hashed or non-hashed * * Return: true if region is valid, false otherwise */ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, - bool route, bool ipv6, bool hashed); + bool route); + +#ifdef IPA_VALIDATE /** * ipa_cmd_data_valid() - Validate command-realted configuration is valid @@ -82,13 +80,6 @@ bool ipa_cmd_data_valid(struct ipa *ipa); #else /* !IPA_VALIDATE */ -static inline bool ipa_cmd_table_valid(struct ipa *ipa, - const struct ipa_mem *mem, bool route, - bool ipv6, bool hashed) -{ - return true; -} - static inline bool ipa_cmd_data_valid(struct ipa *ipa) { return true; diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index c617a9156f26..4f5b6749f6aa 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -161,7 +161,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) else size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64); - if (!ipa_cmd_table_valid(ipa, mem, route, ipv6, hashed)) + if (!ipa_cmd_table_valid(ipa, mem, route)) return false; /* mem->size >= size is sufficient, but we'll demand more */