Skip to contentSkip to conversation

net: rose: fix OOB read in CCITT facility parsing

PATCH In review Tanuj Sharma 4 participants 5 messages Nov 23 – Nov 30 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: rose: fix OOB read in CCITT facility parsing

In rose_parse_ccitt(), the 0xC0 (variable-length) case validates that len >= 2 and that the length field l is in range [10, 20], but does not check that the remaining buffer can actually hold l + 2 bytes before performing memcpy operations at offsets p+7 and p+12.

With a short facilities field (e.g. 2 bytes) and l=10, the memcpy calls read up to 15 bytes past the buffer, leaking adjacent heap data into the facilities struct. This data is then copied to the socket and can be read by userspace via getsockname()/getpeername().

Add the same bounds check that rose_parse_national() already uses for its own 0xC0 case: if (len < 2 + l) return -1.

This code was removed from mainline by commit dd8d4bc28ad72 but remains in the 6.12 LTS branch and all prior LTS branches.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/rose/rose_subr.c | 2 ++
 1 file changed, 2 insertions(+)
net/rose/rose_subr.c +2 -0
index XXXXXXX..XXXXXXX 100644
@@ -369,6 +369,8 @@ static int rose_parse_ccitt(unsigned char *p,
 			/* Prevent overflows*/
 			if (l < 10 || l > 20)
 				return -1;
+			if (len < 2 + l)
+				return -1;
 
 			if (*p == FAC_CCITT_DEST_NSAP) {
 				memcpy(&facilities->source_addr, p + 7, ROSE_ADDR_LEN);

--
2.43.0

#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
maintainer
#2 lore raw
In reply to Tanuj Sharma
Quoted 16 lines · Tanuj Sharma

In rose_parse_ccitt(), the 0xC0 (variable-length) case validates that len >= 2 and that the length field l is in range [10, 20], but does not check that the remaining buffer can actually hold l + 2 bytes before performing memcpy operations at offsets p+7 and p+12.

With a short facilities field (e.g. 2 bytes) and l=10, the memcpy calls read up to 15 bytes past the buffer, leaking adjacent heap data into the facilities struct. This data is then copied to the socket and can be read by userspace via getsockname()/getpeername().

Add the same bounds check that rose_parse_national() already uses for its own 0xC0 case: if (len < 2 + l) return -1.

This code was removed from mainline by commit dd8d4bc28ad72 but remains in the 6.12 LTS branch and all prior LTS branches.

Quoted 6 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/rose/rose_subr.c | 2 ++
 1 file changed, 2 insertions(+)

This file is no longer in the tree, please submit this to the out-of-tree repo that is keeping this codebase alive as it does send patches back to the stable kernel trees quite often.

thanks,

greg k-h

Reviewed-by
#3 lore raw

Hi Tanuj,

Thank you for the fix. I take care of the ROSE code in the out-of-tree repository Greg mentioned, and I run these modules on a small ROSE/FPAC network, so here is a review.

The bug is real. rose_parse_ccitt() never checks that the 0xC0 entry fits in what is left of the facilities field, while rose_parse_national() does. I reproduced it in user space by building rose_parse_facilities(), rose_parse_national() and rose_parse_ccitt() unchanged with AddressSanitizer: a 4-byte facilities field "00 0F C9 0A" (CCITT, DEST_NSAP, l = 10, the 10 bytes missing) at the end of the buffer gives a heap-buffer-overflow read in rose_parse_ccitt() (the memcpy() from p + 7). With your patch the entry is rejected and AddressSanitizer stays quiet.

Two points in the commit message are not right, though:

- It is not only 6.12 and older. 6.18.y has the same code (checked in v6.18.65), and so does the out-of-tree repository.

- The data read past the buffer does not reach user space. When rose_parse_ccitt() returns more than it was given, rose_parse_facilities() catches it with
WARN_ON(len >= facilities_len) and returns 0. Both callers, rose_rx_call_request() and rose_route_frame(), then clear the call, and the facilities struct, a local variable, is dropped. getsockname() and getpeername() never see it. The user-space test above goes the same way: the WARN_ON fires and the parse fails.

So the effect is an out-of-bounds read of up to about 20 bytes past the facilities field, and a WARN that any ROSE neighbour can trigger from the air or over AXUDP with a crafted CALL REQUEST, which means a reboot on a system with panic_on_warn set. That is still worth fixing, and your two lines are the right fix.

As Greg said, please open a pull request at

https://github.com/linux-netdev/mod-orphan

with the commit message updated as above (and the answer to the netdev bot's question about how the bug was found). Once it is merged there, it will go to the stable maintainers for 6.12.y and 6.18.y with the next batch of fixes from that repository. If you would rather not deal with GitHub, tell me and I will carry it there with you as the author.

73 de Bernard, F6BVP

#5 lore raw
In reply to a message not in the archive

Hi Tanuj,

Thank you for the answer.

One thing to know before you open the pull request: the mod-orphan main branch has moved since your patch.
While reviewing your fix, I found two smaller bounds problems in the same facility parsing code.
They are independent of yours, and they were merged today as pull request #96:

04f81e5 rose: test the length before the next byte in the facility loops b4451d3 rose: count the length byte when checking the facilities length

The first one changes the loop condition in rose_parse_national() and rose_parse_ccitt() to "len > 0 && *p != 0x00", so the byte after the field is no longer read when nothing is left.
The second one makes rose_parse_facilities() reject facilities_len == packet_len, which was accepted with one byte missing.

They complement your fix and do not replace it.
The 0xC0 case of rose_parse_ccitt() still has no "len < 2 + l" check on the current main, and your two lines still apply cleanly on top. Please base your branch on the current main.

Once your pull request is merged, I will send it to the stable maintainers for 6.12.y and 6.18.y together with these two commits.

73 de Bernard, F6BVP