From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 661657BB1B; Wed, 21 Feb 2024 14:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525149; cv=none; b=kTUt7fbHA74HS6yVwhJrXjRYSvmmYgQeKZ2AGi8rFoOyPz2vv6O9UdJ22dmz4YjsmKfr5lD77DO74LLg7I5R9TIRYc702TPeIgtn6ADxuR5EyRwRtFJTlwLfHzx4tE5rCyEv3k2Gu5GAyEIwJA6o5EAAAJzt96CUbU3jMZTZLGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525149; c=relaxed/simple; bh=1IY4d0k13MTJHOBn9yv0dlnQXoB0LwhcoQpB6QIInmk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tcizz73P0k2mp7qeYrPH58BeAQ7T+yNGsAIfwkAOV0Ll2iDhGHW2rLeFfTcuW7uDZXorqaHudOROsrRpM0Ssph3hqGyxqXARUBq9Zr6/SrHbPtTNvgdo2tQhrxAyXz663FHNat5kvUUN5wJgA7jqtrNDdMYjG0lPBxKww2nQQOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AQeWmDIv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="AQeWmDIv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA287C43394; Wed, 21 Feb 2024 14:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525149; bh=1IY4d0k13MTJHOBn9yv0dlnQXoB0LwhcoQpB6QIInmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQeWmDIvyJRwocxJdUmcU9vJl7M1Nwx8JmK719widDTUQZZvbSGsYWLM8ISAiou2Z lQ0kuC+D4EQ4kpvdgW4ctZdVZk/itRTy7SSUqwvvUYYRmyiTQW2GG5xNZsQQMx6zzC CPb7wz8ct67oc19M2PsDw770rNLaXQhbCxUfDi4U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Notselwyn , Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 5.4 047/267] netfilter: nf_tables: reject QUEUE/DROP verdict parameters Date: Wed, 21 Feb 2024 14:06:28 +0100 Message-ID: <20240221125941.489419143@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal commit f342de4e2f33e0e39165d8639387aa6c19dff660 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -8058,16 +8058,10 @@ static int nft_verdict_init(const struct 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: @@ -8087,6 +8081,8 @@ static int nft_verdict_init(const struct data->verdict.chain = chain; break; + default: + return -EINVAL; } desc->len = sizeof(data->verdict);