History

net/sched: cls_u32: validate offshift to prevent shift-out-of-bounds

u32_change() copies the user-provided tc_u32_sel.offshift (unsigned char, 0-255) into the kernel knode object without bounds validation. When a packet later hits u32_classify() with TC_U32_VAROFFSET set, it evaluates `ntohs(offmask & *data) >> offshift` where the left operand is a 16-bit value promoted to a 32-bit int. Any offshift >= 32 is undefined behavior per C11 6.5.7p3, triggerable by an unprivileged user via user/network namespaces. UBSAN: shift-out-of-bounds in net/sched/cls_u32.c:236:43 shift exponent 32 is too large for 32-bit type int Fix this by rejecting offshift >= 16 during filter creation in u32_change().

Cen Zhang (Microsoft) committed 3 months ago

Commit aef96ee1 parent 295dd291 file · +7 −0Browse files

Unified · Split

net/sched/cls_u32.c+7−0
@@ -1107,6 +1107,13 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, · 1106 unmodified lines
11071107 goto erridr;
11081108 }
11091109
1110+ if (s->offshift >= 16) {
1111+ NL_SET_ERR_MSG_MOD(extack,
1112+ "offshift must be less than 16");
1113+ err = -EINVAL;
1114+ goto erridr;
1115+ }
1116+
11101117 n = kzalloc_flex(*n, sel.keys, s->nkeys);
11111118 if (n == NULL) {
11121119 err = -ENOBUFS;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t