From patchwork Fri Feb 9 21:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1897220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TWmkl0nydz23hf for ; Sat, 10 Feb 2024 08:11:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rYY9u-0001AI-NK; Fri, 09 Feb 2024 21:11:43 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rYY9i-00019n-Ie for kernel-team@lists.ubuntu.com; Fri, 09 Feb 2024 21:11:32 +0000 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 5FE3B3FE39 for ; Fri, 9 Feb 2024 21:11:29 +0000 (UTC) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-68c51abe499so22618856d6.2 for ; Fri, 09 Feb 2024 13:11:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707513088; x=1708117888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xJMRkhjxKDLSixF4pCTie8LexG5Pv6j31hgC6YNIsqc=; b=ANk0v2GlDLSMGDXIi0YqGxMM5bWTSll9tMHC2Njw/uHma+JmdGz5I8YpziUOilnJSn +Hk46Sh3WP2CvUI7p1l2N9nrtJvvFCIGOaqIMnb5j84wzFz/kosRdTmUHSFMereKrJnh Ie8KTZQAnv2BAHRxSAS79tTGcN0byEZzGIM6gzUxEwA6ro0sk1BxqhDHldrSi5esQkAw k+hI4pcWmzEOePRgmF11VTyJZruKJvj9wBd9dpxJDejkm0coawscBsyEsFSd7jL7DApd AWizQfI46grUrwqcxZVc937NRgXUMmlLCtljMZ799gtTokHQocNq1xEVQj3L75IyUtf1 N2qQ== X-Gm-Message-State: AOJu0Yz+Uo5iewHFPoKiqkNbT7yoeMFHthFDgoP3OUg11I7wDwZvW7Fb +rLFVTyVworPAOWlK3/FoQ+BOAKR7sKQ607GnveXO/saDqd376ZTR4G7zPiislbBaXeGxwasD8z WZglJnLVs8KeiAOYhNPVzra8jRG9Sln2QYHd32lSA4fp2pAQeW47VGLOh4csU64QDk4R1OpNe6m +vQvQu6M6LuQ== X-Received: by 2002:a05:6214:3908:b0:68c:a9bb:25af with SMTP id nh8-20020a056214390800b0068ca9bb25afmr449269qvb.11.1707513088295; Fri, 09 Feb 2024 13:11:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjirw/sxjqvsIpYrvY0Bh688ZcHIoLfwqOjATJ/fyCZN7F0uyYRylv3rk9DsU2W5ar7IbHGQ== X-Received: by 2002:a05:6214:3908:b0:68c:a9bb:25af with SMTP id nh8-20020a056214390800b0068ca9bb25afmr449256qvb.11.1707513088039; Fri, 09 Feb 2024 13:11:28 -0800 (PST) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id mv7-20020a056214338700b00686965d4be0sm1171080qvb.90.2024.02.09.13.11.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:11:27 -0800 (PST) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 1/1] netfilter: nf_tables: reject QUEUE/DROP verdict parameters Date: Fri, 9 Feb 2024 15:11:25 -0600 Message-Id: <20240209211125.56995-3-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240209211125.56995-1-bethany.jamison@canonical.com> References: <20240209211125.56995-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Florian Westphal This reverts commit e0abdadcc6e1. core.c:nf_hook_slow assumes that the upper 16 bits of NF_DROP verdicts contain a valid errno, i.e. -EPERM, -EHOSTUNREACH or similar, or 0. Due to the reverted commit, its possible to provide a positive value, e.g. NF_ACCEPT (1), which results in use-after-free. Its not clear to me why this commit was made. NF_QUEUE is not used by nftables; "queue" rules in nftables will result in use of "nft_queue" expression. If we later need to allow specifiying errno values from userspace (do not know why), this has to call NF_DROP_GETERR and check that "err <= 0" holds true. Fixes: e0abdadcc6e1 ("netfilter: nf_tables: accept QUEUE/DROP verdict parameters") Cc: stable@vger.kernel.org Reported-by: Notselwyn Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso (backported from commit f342de4e2f33e0e39165d8639387aa6c19dff660) [bjamison: context conflict - upstream had changed the implicit 'fallthrough' in the switch to explicit but the fix commit removes the switch completely so I accepted the fix's incoming changes] CVE-2024-1086 Signed-off-by: Bethany Jamison --- net/netfilter/nf_tables_api.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index a7d6692cf451..fa6e1732e222 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -8080,16 +8080,10 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data, data->verdict.code = ntohl(nla_get_be32(tb[NFTA_VERDICT_CODE])); switch (data->verdict.code) { - default: - switch (data->verdict.code & NF_VERDICT_MASK) { - case NF_ACCEPT: - case NF_DROP: - case NF_QUEUE: - break; - default: - return -EINVAL; - } - /* fall through */ + case NF_ACCEPT: + case NF_DROP: + case NF_QUEUE: + break; case NFT_CONTINUE: case NFT_BREAK: case NFT_RETURN: @@ -8109,6 +8103,8 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data, data->verdict.chain = chain; break; + default: + return -EINVAL; } desc->len = sizeof(data->verdict);