From nobody Wed Sep 3 02:01:30 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F05DC38145 for ; Fri, 2 Sep 2022 12:31:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236734AbiIBMbF (ORCPT ); Fri, 2 Sep 2022 08:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236345AbiIBMab (ORCPT ); Fri, 2 Sep 2022 08:30:31 -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 CCC07DF64F; Fri, 2 Sep 2022 05:26:02 -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 CFF55620E6; Fri, 2 Sep 2022 12:24:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E376EC433C1; Fri, 2 Sep 2022 12:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121460; bh=nWRoO5ttH0qgnkkzYxYakfYShlDNVFZKpmajFJ1cLSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eu6OvrTRjz+U1olPQLAyypXq1o+/Ws1+KgcNqwbUxC1yGmROjqVcpaNxm5Z5Wb2Qe vML210XnX+AldWbIa1V0sOKT43CeMo7DdTImZ3mHMD2JmWobSppuc1QfzCa7CPnsNd WGuXnsTo836m2x06sC471sJh9ro/qHxAxNxJ5JFA= 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 4.19 15/56] netfilter: nft_payload: report ERANGE for too long offset and length Date: Fri, 2 Sep 2022 14:18:35 +0200 Message-Id: <20220902121400.699491043@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121400.219861128@linuxfoundation.org> References: <20220902121400.219861128@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 fd87216bc0a99..04b9df9e39554 100644 --- a/net/netfilter/nft_payload.c +++ b/net/netfilter/nft_payload.c @@ -398,6 +398,7 @@ nft_payload_select_ops(const struct nft_ctx *ctx, { enum nft_payload_bases base; unsigned int offset, len; + int err; =20 if (tb[NFTA_PAYLOAD_BASE] =3D=3D NULL || tb[NFTA_PAYLOAD_OFFSET] =3D=3D NULL || @@ -423,8 +424,13 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (tb[NFTA_PAYLOAD_DREG] =3D=3D NULL) return ERR_PTR(-EINVAL); =20 - offset =3D ntohl(nla_get_be32(tb[NFTA_PAYLOAD_OFFSET])); - len =3D ntohl(nla_get_be32(tb[NFTA_PAYLOAD_LEN])); + err =3D nft_parse_u32_check(tb[NFTA_PAYLOAD_OFFSET], U8_MAX, &offset); + if (err < 0) + return ERR_PTR(err); + + err =3D nft_parse_u32_check(tb[NFTA_PAYLOAD_LEN], U8_MAX, &len); + if (err < 0) + return ERR_PTR(err); =20 if (len <=3D 4 && is_power_of_2(len) && IS_ALIGNED(offset, len) && base !=3D NFT_PAYLOAD_LL_HEADER) --=20 2.35.1