Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3083379rwe; Mon, 29 Aug 2022 05:40:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NsuFYCI2frQfubg89lPn1bmkvEulP2IlBJkOrUeRDFFpUv8oKQPCYBifo2ZK+ykIOqm5V X-Received: by 2002:a63:e011:0:b0:42a:1c12:17a9 with SMTP id e17-20020a63e011000000b0042a1c1217a9mr13550398pgh.557.1661776809799; Mon, 29 Aug 2022 05:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776809; cv=none; d=google.com; s=arc-20160816; b=SY8qhntAMVzZ1e0m61rhQSSs288o1RwDd2B+0hLOyv70XoueeobnOdrFaFNIDq53L+ IIB9AGddNZubY0t0rWsDZpE2c4LH0C6CMkah/wWBeDudGjkY4Qd5H+4wwi4jbUg8GB3w qh91hbooT53LBROoGf9vpcxW7/n5Iz38jQf1zGAtFaL+6nkqT6D4g4F6ZhYy/hb0BjIn kH+BZURlF+RmYU/RY+Od9xrz19Kth3CtCqmS0hdZaxoxqT2jU4WucnCLA2DEl9OJjxwp 4FTZznQkRm+ZuX6oCPGpMz/M6MMdpd9hC+Ml+mYv8z2t4kzd6Y19k1e0PvWwkBPPUFXm FPEA== 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=UQ+68PrABgAPPrAGUS3X7Lgkf/DFSWxr7OcIOfi8YOM=; b=UX/S/+SzhyseYWxPQuFW3x+n5s0AIgdgoIkd4O6hfDySU3t39eeuHONu6/Xh/fhBmW GLznoo+8glEKZ1s7qbi4yH/0Ks/y5/lF4DPnLOzLdF9x4JjaUeyf1YvftrsfncCYNLvY dU0G++YavVcvuxgRswk/WTfhscV0fI+y/qHuCfyXBaNoKYe04mjCGRvjJckWYt1bpGob ApQNTf6R4waTs53erwtfV8NpOZ3OdegnO+UC6a1TOPZiBFEhAL1CEfMMaDE6zk8l9iCF dZ5/LX8LNRPAI9xiQAJ8TPoEgViruTJ4f3tYWrRFE2QZDgndBB3srzo+mqEnII/ZNF0Y ZKNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GQUUBLsf; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020aa78dca000000b00537bb009bebsi8061630pfr.287.2022.08.29.05.39.58; Mon, 29 Aug 2022 05:40:09 -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=@linuxfoundation.org header.s=korg header.b=GQUUBLsf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231463AbiH2LUo (ORCPT + 99 others); Mon, 29 Aug 2022 07:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbiH2LTM (ORCPT ); Mon, 29 Aug 2022 07:19:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E582753A7; Mon, 29 Aug 2022 04:13:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E73E4611D7; Mon, 29 Aug 2022 11:05:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDE78C433C1; Mon, 29 Aug 2022 11:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771153; bh=qQRB+uJ/BFvcwnf2Xmkqk11LcMxxR69ZBCfWEdf6GEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQUUBLsfMxLvMErLzkd5DFfe3n09SZcdJraz9GCpYT/29Qg2PPB6Ug0ykpnyGoqJt UdXe6kyUm+7G1KLmGa/E8wUJJHkEaJVFKfxBRjPxgOKvOnee7YbVfex9v8+k1lkpCk HT7OGfb/YCZAdgqeE8NxMzAZuJ0Uap0k8lCJBd9c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.10 32/86] netfilter: nft_payload: report ERANGE for too long offset and length Date: Mon, 29 Aug 2022 12:58:58 +0200 Message-Id: <20220829105757.868827229@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Pablo Neira Ayuso [ Upstream commit 94254f990c07e9ddf1634e0b727fab821c3b5bf9 ] Instead of offset and length are truncation to u8, report ERANGE. Fixes: 96518518cc41 ("netfilter: add nftables") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_payload.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c index 01878c16418c2..bdb07362c0ef0 100644 --- a/net/netfilter/nft_payload.c +++ b/net/netfilter/nft_payload.c @@ -733,6 +733,7 @@ nft_payload_select_ops(const struct nft_ctx *ctx, { enum nft_payload_bases base; unsigned int offset, len; + int err; if (tb[NFTA_PAYLOAD_BASE] == NULL || tb[NFTA_PAYLOAD_OFFSET] == NULL || @@ -758,8 +759,13 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (tb[NFTA_PAYLOAD_DREG] == NULL) return ERR_PTR(-EINVAL); - offset = ntohl(nla_get_be32(tb[NFTA_PAYLOAD_OFFSET])); - len = ntohl(nla_get_be32(tb[NFTA_PAYLOAD_LEN])); + err = nft_parse_u32_check(tb[NFTA_PAYLOAD_OFFSET], U8_MAX, &offset); + if (err < 0) + return ERR_PTR(err); + + err = nft_parse_u32_check(tb[NFTA_PAYLOAD_LEN], U8_MAX, &len); + if (err < 0) + return ERR_PTR(err); if (len <= 4 && is_power_of_2(len) && IS_ALIGNED(offset, len) && base != NFT_PAYLOAD_LL_HEADER) -- 2.35.1