Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412930rwa; Tue, 23 Aug 2022 04:29:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NBK1FxYzcWQUQSt+DIKKdBR3zaiqKBWFUsW6nbfBrq75h1INWNunwcOr0pZyRiJANKbgh X-Received: by 2002:a17:906:9c82:b0:6df:baa2:9f75 with SMTP id fj2-20020a1709069c8200b006dfbaa29f75mr16719656ejc.762.1661254150122; Tue, 23 Aug 2022 04:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254150; cv=none; d=google.com; s=arc-20160816; b=d6aUlT5vfQjHZKYEVFqyA31AELJP+XQit4VzoCFTcrp3A4+yaXay9Zpy0W/Ur1cHCG MPoWlFseaGIDLXwtMn8y2ULnjHBazyv6hxq6YVOPy2OuO+Ci7kj/y/EGffJdB4bgsAWD 4LSzxmOiYbW2Di1fMcC5/lVrObJuIsz/lUPLERlNJYyo4XVZzEQ/jnJvGJSbh2ZoAhnD d6HQK2ISgVx6hAtaEbN0DZrQL2QXVWTsZ6OxP8k4ZmpSXYxDonWV6DiglJdLPb/phqbC OjWrt8sHDOzIAp9XUvX547bJjD0d+BX4+GBTPhPc42oJQsIUJuxDTiveNYXVNbADnwCj lTVQ== 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=f55q/ClllyEg4d8oNa7lUrKhvAjAajkUCo9jb9azFEg=; b=BlyB8DDiVEqiZViLeZmCMcp1QMWBqv2o9r2s5KFuzCF3V07xyiT6XUKknn8s0Nelje BhRIg+o/FFElkZg8m1eKA74c4kUtIOiHjvzQfrc9G9uZvfBIoBCxJk3sY7KqAOLtK5lG H6RasBz8T7Lp68E9q2nAjrw4SI3j+54J+dhApzYmASu2c1YMuwRHxgaW8FKgPBGh6nMy 6JYg5c4YZKmmlcWew4N+qimoh7C4J8oSDd14YZuvvMGFuQRfTfhdY1T7vg5YGWoVPDm9 V7vZzbIbJMyXTOdlXY/AttJZ7s9WEKWY0hAZH/50HOoT09wD3vB/t32fNG2rLirrPDtR scLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WnKYaV/z"; 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 ww7-20020a170907084700b007312789a037si11848895ejb.144.2022.08.23.04.28.43; Tue, 23 Aug 2022 04:29:10 -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="WnKYaV/z"; 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 S1350945AbiHWJdJ (ORCPT + 99 others); Tue, 23 Aug 2022 05:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351231AbiHWJb0 (ORCPT ); Tue, 23 Aug 2022 05:31:26 -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 DA818275F1; Tue, 23 Aug 2022 01:38:38 -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 39DDB61547; Tue, 23 Aug 2022 08:37:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29CF5C433C1; Tue, 23 Aug 2022 08:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243828; bh=yMu/+1FFUxvoYGpo6+tLh1Im8+eo2FszMBiGdkHivVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WnKYaV/zKw0R+Hpua2nqq8w3L79HSzbZ1ikOsrSE4YjV60IsNcaEwTN1lVnd2KOVo b2IgBi7h5lLZNr/cU9ZKWs3DZmBrTtWcyGHGYB6BiWaV8cRXDYaPSGaMPrWtgTNFRU Y6bMdyw5buT8LWcRK25pEWTlAizY1n++0rymH0ws= 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 4.14 007/229] netfilter: nf_queue: do not allow packet truncation below transport header offset Date: Tue, 23 Aug 2022 10:22:48 +0200 Message-Id: <20220823080053.580178437@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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: 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 ba74bb2d6341..369f1634afe9 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -827,11 +827,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