Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3054701rwe; Mon, 29 Aug 2022 05:13:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4mGBurywDEOZdGZmce2hQ9BJuDpxNieM7W3Iprizuc4Rr7o40VGD7Y5/wMFVRlNc9ldLS9 X-Received: by 2002:a17:90b:3911:b0:1fb:23c1:2ec6 with SMTP id ob17-20020a17090b391100b001fb23c12ec6mr18275093pjb.45.1661775193626; Mon, 29 Aug 2022 05:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775193; cv=none; d=google.com; s=arc-20160816; b=ySVGkif/2BtzCXrXqt5/gybPZxi/LYbFgVijoWptikqZmen7fD2acCD0LnlvgW9ynM bLPqvX8Tw/ExUdPjZ7hmRKTSqGNKMCecBphpdgDm+OOexDNpcHLupfw8CY9pd8PwZZj8 iW6hzG2yiVYJlhWY6K/nRj8nAbLldLQcbv5MNDNTVWajxdPpZILpfGTc5sXsfDpV79jJ 8KbJLSd8Hhgx/jCZgZ7/XwMzEUxj0UFjXdfKm2rAXAt1RAtes9KgFp6C1F36CvIZ5E/5 poluifUr+L5z5DU3he8ah76m6XnjAKzrDJgyMWbMjk3Rkxdg+O+J0eqcDIbTF5fWIqWQ 1KcA== 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=gige7hVI6C4BeR+oq4acjNDg1I+040+YQpgooayrtts=; b=m468MGUG2yz8RrOj+j8aqoaKlaE/neq/dqcL0aYirkqVHTXdAsuxNPhVzJe2gB14Nn UMl/h0PGRXetqmS9y3QWsW/JIKBHVOxmJsNL0yFiB/1uc/b2FuWkoLij5bjHpxXtJ70w WRrvrxko037eMhjNEdBynlEhnOSxFUyfzwoxHuAd3JkeTO1E4qKz92Gb3FWCNTqHfJ4+ rEOpdUnrY8e4Dmh2Qv9DFHm9KDWvGi8BnphiR1+EAqkzFVPkA+dsUufUjc61KZz5fmWJ qKYqhTFOX6x12KLb6Am7vbSTR+CNtqfVpReYjIvaeluZc73K6EdLBAOVCUNdbdvZDkyD i3Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yOi/wrqc"; 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 n10-20020a170902f60a00b0016dd4c3c2e2si8884813plg.488.2022.08.29.05.12.54; Mon, 29 Aug 2022 05:13:13 -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="yOi/wrqc"; 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 S232137AbiH2L0p (ORCPT + 99 others); Mon, 29 Aug 2022 07:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbiH2LYa (ORCPT ); Mon, 29 Aug 2022 07:24:30 -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 94D4F6527A; Mon, 29 Aug 2022 04:15:40 -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 3AD566122B; Mon, 29 Aug 2022 11:14:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44F8AC433C1; Mon, 29 Aug 2022 11:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771656; bh=weqIPM4w2R7i+ut6+CsVGklhQR7rTe/r0eAyyVTjtBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yOi/wrqc81C0RQS/KxngIU4eamgSgaDAmaqLdLMReTM8BVV+60ZCUWmP1MOcgZVpo XILiCXMfVbjQ2kyo4lww6oN6UaCoCRgV7RRL9gGGX+T747zm26rFFwCh2JhjDHQxVi OM0tSBRnZsZ3migoFVyIeFbUdZVOa1TudLc1RmgY= 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.19 057/158] netfilter: nft_payload: report ERANGE for too long offset and length Date: Mon, 29 Aug 2022 12:58:27 +0200 Message-Id: <20220829105811.118155593@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 2e7ac007cb30f..4fee67abfe2c5 100644 --- a/net/netfilter/nft_payload.c +++ b/net/netfilter/nft_payload.c @@ -833,6 +833,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 || @@ -859,8 +860,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 && base != NFT_PAYLOAD_INNER_HEADER) -- 2.35.1