Skip to content

Commit 910c33e

Browse files
Muhammad Bilalgregkh
authored andcommitted
netfilter: nf_conntrack_irc: fix parse_dcc() off-by-one OOB read
commit ef6400c upstream. parse_dcc() treats data_end as an inclusive end pointer, but its only caller passes data_limit = ib_ptr + datalen, which points one past the last valid byte. The newline search loop iterates while tmp <= data_end, so when no newline is present, *tmp is read at tmp == data_end, one byte beyond the region filled by skb_header_pointer(). irc_buffer is kmalloc'd as MAX_SEARCH_SIZE + 1 bytes and datalen is capped at MAX_SEARCH_SIZE, so the stray read does not fault. The byte is uninitialized or stale; if it contains an ASCII digit, simple_strtoul will consume it and produce a wrong DCC IP or port in the conntrack expectation. The extra allocation byte is also a fragile guard: if the cap or allocation size changes, this becomes a real out-of-bounds read. Change the loop and its post-loop check to use strict less-than, consistent with the caller's exclusive-end convention. Update the function comment accordingly. Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Muhammad Bilal <meatuni001@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a164e74 commit 910c33e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

net/netfilter/nf_conntrack_irc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const char *const dccprotos[] = {
6464
/* tries to get the ip_addr and port out of a dcc command
6565
* return value: -1 on failure, 0 on success
6666
* data pointer to first byte of DCC command data
67-
* data_end pointer to last byte of dcc command data
67+
* data_end one past end of data
6868
* ip returns parsed ip of dcc command
6969
* port returns parsed port of dcc command
7070
* ad_beg_p returns pointer to first byte of addr data
@@ -82,10 +82,10 @@ static int parse_dcc(char *data, const char *data_end, __be32 *ip,
8282

8383
/* Make sure we have a newline character within the packet boundaries
8484
* because simple_strtoul parses until the first invalid character. */
85-
for (tmp = data; tmp <= data_end; tmp++)
85+
for (tmp = data; tmp < data_end; tmp++)
8686
if (*tmp == '\n')
8787
break;
88-
if (tmp > data_end || *tmp != '\n')
88+
if (tmp >= data_end || *tmp != '\n')
8989
return -1;
9090

9191
*ad_beg_p = data;

0 commit comments

Comments
 (0)