Skip to contentSkip to conversation

net_sched: reject TCF_EM_SIMPLE case for complex ematch module

PATCH Applied Cong Wang 3 participants 3 messages Dec 17, 2022 – Dec 19, 2022

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: reject TCF_EM_SIMPLE case for complex ematch module

From: Cong Wang <[email protected]>

When TCF_EM_SIMPLE was introduced, it is supposed to be convenient for ematch implementation:

https://lore.kernel.org/all/[email protected]/

"You don't have to, providing a 32bit data chunk without TCF_EM_SIMPLE set will simply result in allocating & copy. It's an optimization, nothing more."

So if an ematch module provides ops->datalen that means it wants a complex data structure (saved in its em->data) instead of a simple u32 value. We should simply reject such a combination, otherwise this u32 could be misinterpreted as a pointer.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-and-tested-by [email protected]
Cc Jamal Hadi Salim <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 net/sched/ematch.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/ematch.c +2 -0
index 4ce681361851..5c1235e6076a 100644
@@ -255,6 +255,8 @@ static int tcf_em_validate(struct tcf_proto *tp,
 			 * the value carried.
 			 */
 			if (em_hdr->flags & TCF_EM_SIMPLE) {
+				if (em->ops->datalen > 0)
+					goto errout;
 				if (data_len < sizeof(u32))
 					goto errout;
 				em->data = *(u32 *) data;
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 31 lines · Cong Wang

From: Cong Wang <[email protected]>

When TCF_EM_SIMPLE was introduced, it is supposed to be convenient for ematch implementation:

https://lore.kernel.org/all/[email protected]/

"You don't have to, providing a 32bit data chunk without TCF_EM_SIMPLE set will simply result in allocating & copy. It's an optimization, nothing more."

So if an ematch module provides ops->datalen that means it wants a complex data structure (saved in its em->data) instead of a simple u32 value. We should simply reject such a combination, otherwise this u32 could be misinterpreted as a pointer.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-and-tested-by [email protected]
Cc Jamal Hadi Salim <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 net/sched/ematch.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/ematch.c +0 -0
index 4ce681361851..5c1235e6076a 100644

net/sched/ematch.c static int tcf_em_validate(struct tcf_proto *tp, · line 262

Quoted 8 lines
net/sched/ematch.c +2 -0
@@ -255,6 +255,8 @@ static int tcf_em_validate(struct tcf_proto *tp,
 			 * the value carried.
 			 */
 			if (em_hdr->flags & TCF_EM_SIMPLE) {
+				if (em->ops->datalen > 0)
+					goto errout;
 				if (data_len < sizeof(u32))
 					goto errout;
 				em->data = *(u32 *) data;

The patch LGTM, thanks!

If I read correctly, this effectively rejects any ematch with TCF_EM_SIMPLE set (all the existing tcf_ematch_ops structs have eiter .change or . datalen > 0).

It looks like EM_SIMPLE does not work as intended since a lot of time (possibly since its introduction !?!). Can we drop it completely?

Cheers,

Paolo

#2 lore raw
In reply to Cong Wang
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 8 lines · On Sat, 17 Dec 2022 14:17:07 -0800 you wrote:

From: Cong Wang <[email protected]>

When TCF_EM_SIMPLE was introduced, it is supposed to be convenient for ematch implementation:

https://lore.kernel.org/all/[email protected]/

[...]

Here is the summary with links:
- [net] net_sched: reject TCF_EM_SIMPLE case for complex ematch module

    https://git.kernel.org/netdev/net/c/9cd3fd2054c3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html