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 AD58C1E4B2; Wed, 21 Feb 2024 13:30:52 +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=1708522252; cv=none; b=QI4ZVczYQ6V0pSRoX6WDsR9cXmo4vXZBDJCpSy+ZbHf1qgGr5FlHnVVTJ8Qj1kQEjdbCNrI/nzXQ0ZYMoM94z0SLYFUVPqWMDwwsPg1As3IISs17P8KkTBsoyxIdPSHYCIFObyLOVdmuP3pK4jh8+lDY35XNknyu7wXb0x1TTxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708522252; c=relaxed/simple; bh=kB5nK/K8kBHBHi5ltUT+r3WHlUEFFDx4d9K747QrlS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQ5X/ZzF5MRpXUqwSk9OV50ts3fOAWtYhTkChd/4gCIc1HpO3xpVKIrwX+t9r3y/9vr/Rz0JiBlksO75pp4x0Lr/ThGSZI8sZxc9cgWnSNQrrny4cugz20StYBUeEoOguT7/YXezLXKGm2A/boLa8dPgNRYRBrSYaSlkkgHjpUM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=S/kk9vbS; 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="S/kk9vbS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19A8BC433F1; Wed, 21 Feb 2024 13:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708522252; bh=kB5nK/K8kBHBHi5ltUT+r3WHlUEFFDx4d9K747QrlS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S/kk9vbSGPBKXNg/YjOGinsYCAE7zmchzx5UIIE0dyBRQvLbTekmP5+JI1EvLMQQJ eJrRj3mbgGUpoqRG2e0aDJ/TQhRfy47Dt+mQry0HwUwuFh2QbiaKXokO1ZJP0FRcCq mVC5vHOE+bepWlDybaj/C3Zo4CEpXnWEoQLihhuc= 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.15 087/476] netfilter: nf_tables: reject QUEUE/DROP verdict parameters Date: Wed, 21 Feb 2024 14:02:18 +0100 Message-ID: <20240221130011.203154236@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221130007.738356493@linuxfoundation.org> References: <20240221130007.738356493@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.15-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 @@ -10251,16 +10251,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; - } - fallthrough; + case NF_ACCEPT: + case NF_DROP: + case NF_QUEUE: + break; case NFT_CONTINUE: case NFT_BREAK: case NFT_RETURN: @@ -10295,6 +10289,8 @@ static int nft_verdict_init(const struct data->verdict.chain = chain; break; + default: + return -EINVAL; } desc->len = sizeof(data->verdict);