Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1942329imn; Mon, 1 Aug 2022 05:52:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vojfwNKipcb04FkkQSQwuEGaS4eNxicSLeC3xuLefieFK70cWB1YnBiE4TO0Z+llNoNYvD X-Received: by 2002:a05:6402:1102:b0:43a:9cf7:68a3 with SMTP id u2-20020a056402110200b0043a9cf768a3mr15731814edv.68.1659358370847; Mon, 01 Aug 2022 05:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358370; cv=none; d=google.com; s=arc-20160816; b=WEJrizMBPyyASzLQfZdK8FwZQB6G82T+qeLegfVex0n4Pvtia5Jb7jfpG5vbq4IYNp YsWrxM43r38iyZN7DVTYXTbxJP+yOKoBogiVf2nNcgCnASC9xqdn8N3gjIm1yI+a1DqX JbN6nU5aWuq1CKyedk/9QCmnYtt+0WlI66AocFGFTRl4jMlocEZ5rh9Ky7ZjZFDmFTK0 RNWn+1EbxRGPFt//BYkXQkKTQPVNekdaIjZ3U0VRGjzVAGABJl3mXcKSgsxXBlaPyYk2 ZunyMIy6j4iQolDJhvhUmcgpJTixSialL93PyRF3VaDIN1a2JCjKQE5D0pYxskeJ0I6g T8Lw== 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=2p9ITHbkjU+YlDAjjb7siefQYH1FlFFywEDNmNw0xpw=; b=ryFcCcvF1SO2gP2tM7vqVWlRmj36hNjcyQeZx9ayiyfUdDtBsas2hl3cLMTIiiBpfF B6JNdrdoEWHzOLWRQI9vRSZatPoi2fZ267yGVlXJQaXGq0TlWR9yjiNAB0y4II2QQwHQ OZD1W9bbiIXNOnU+IwnYq6zKPcNtsrqieq1Y6PVouKVh4FuCkvKVBbHS9t93kcr9GTTP WBCBH8wh0Rr2ozaERQ1oleLHfHLPtxEhxJ09Rff8wGtoXhQHAnY50aaA2k6jTelYEglO i6pnsdz8JLeJipDpGuhwL+RGTHVZzNTeaGhjhWY2ImSAl070RgcAnCxRXBXD078owYwy C+vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k1a/wB85"; 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 l17-20020a056402255100b0043a7351594dsi12040316edb.254.2022.08.01.05.52.26; Mon, 01 Aug 2022 05:52:50 -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="k1a/wB85"; 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 S233509AbiHAMGb (ORCPT + 99 others); Mon, 1 Aug 2022 08:06:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232874AbiHAMFZ (ORCPT ); Mon, 1 Aug 2022 08:05:25 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E4C5A3C6; Mon, 1 Aug 2022 04:54:51 -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 sin.source.kernel.org (Postfix) with ESMTPS id 40812CE1157; Mon, 1 Aug 2022 11:54:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34B51C433C1; Mon, 1 Aug 2022 11:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354888; bh=COGnvKI3TA8NxmZ6PUaCgjEEP6RaalfNvTdWi+lFvrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1a/wB85YDuEC123SWDy94T1LyFTFSiJMwgbKJnxCbdjW/wWMu0GfCIY9joljF5QL T3SWLsFaspnYL5c7BqpD8BOjsU/k+hkBIi2X5KSvD6q8e6h424gALJbzApEGNukpWD mDKSzr3SM/p2Gx4PeBTW98ZsFBM9ZmjUuZy795Hs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Domingo Dirutigliano , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.15 57/69] netfilter: nf_queue: do not allow packet truncation below transport header offset Date: Mon, 1 Aug 2022 13:47:21 +0200 Message-Id: <20220801114136.780889603@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114134.468284027@linuxfoundation.org> References: <20220801114134.468284027@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 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: Florian Westphal [ Upstream commit 99a63d36cb3ed5ca3aa6fcb64cffbeaf3b0fb164 ] Domingo Dirutigliano and Nicola Guerrera report kernel panic when sending nf_queue verdict with 1-byte nfta_payload attribute. The IP/IPv6 stack pulls the IP(v6) header from the packet after the input hook. If user truncates the packet below the header size, this skb_pull() will result in a malformed skb (skb->len < 0). Fixes: 7af4cc3fa158 ("[NETFILTER]: Add "nfnetlink_queue" netfilter queue handler over nfnetlink") Reported-by: Domingo Dirutigliano Signed-off-by: Florian Westphal Reviewed-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nfnetlink_queue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 8787d0613ad8..5329ebf19a18 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -836,11 +836,16 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) } static int -nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff) +nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int diff) { struct sk_buff *nskb; if (diff < 0) { + unsigned int min_len = skb_transport_offset(e->skb); + + if (data_len < min_len) + return -EINVAL; + if (pskb_trim(e->skb, data_len)) return -ENOMEM; } else if (diff > 0) { -- 2.35.1