netfilter: conntrack: validate parsed port values in IRC and Amanda helpers
Subsystems (3)
cover netfilter: conntrack: validate parsed port values in IRC and Amanda helpers
Both nf_conntrack_irc and nf_conntrack_amanda parse port numbers from application-layer protocol data using simple_strtoul(), which returns unsigned long. The results are stored in u16 variables without range checks, silently truncating values above 65535.
This series adds explicit upper-bound validation in both helpers.
Note: checkpatch warns about simple_strtoul being obsolete. Both call sites use the endptr output parameter to advance the parse position, which kstrtoul does not provide. Converting to kstrtoul would require restructuring the parsers, which is out of scope for this fix.
HACKE-RC (2):
netfilter: nf_conntrack_irc: reject DCC port values above 65535
netfilter: nf_conntrack_amanda: reject port values above 65535
net/netfilter/nf_conntrack_amanda.c | 10 ++++++---- net/netfilter/nf_conntrack_irc.c | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-)
Signature · 1 line
2.54.0
Pablo Neira Ayuso
maintainerQuoted 7 lines · HACKE-RC
Both
nf_conntrack_ircandnf_conntrack_amandaparse port numbers from application-layer protocol data usingsimple_strtoul(), which returns unsigned long. The results are stored in u16 variables without range checks, silently truncating values above 65535.This series adds explicit upper-bound validation in both helpers.
Quoted 7 lines
Note: checkpatch warns about
simple_strtoulbeing obsolete. Both call sites use the endptr output parameter to advance the parse position, which kstrtoul does not provide. Converting to kstrtoul would require restructuring the parsers, which is out of scope for this fix.HACKE-RC (2):
HAHA, this nickname is funny, it is making my day here. Thanks!
Quoted 10 lines
netfilter:
nf_conntrack_irc: reject DCC port values above 65535
netfilter:nf_conntrack_amanda: reject port values above 65535net/netfilter/nf_conntrack_amanda.c | 10 ++++++---- net/netfilter/nf_conntrack_irc.c | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-)Signature · 1 line
2.54.0
PATCH 1/2 netfilter: nf_conntrack_irc: reject DCC port values above 65535
In reply to HACKE-RCparse_dcc() stores the return value of simple_strtoul() directly into a u_int16_t pointer. simple_strtoul() returns unsigned long, so values above 65535 are silently truncated when assigned to the u16 output parameter.
Use an intermediate unsigned long variable and reject out-of-range values by returning -1, which causes the caller in help() to skip the DCC command via the existing error path.
The dcc_port == 0 check in help() already rejects port 0, so this change only adds the upper-bound check in the parser.
--- net/netfilter/nf_conntrack_irc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_irc.c +6 -1
@@ -68,6 +68,7 @@ static const char *const dccprotos[] = {static int parse_dcc (char *data,const char *data_end,__be32 *ip,u_int16_t *port,char **ad_beg_p,char **ad_end_p) { +unsigned long parsed_port;char *tmp;/* at least 12: "AAAAAAAA P\1\n" */
@@ -93,7 +94,11 @@ static int parse_dcc(char *data, const char *data_end, __be32 *ip, data++; } - *port =simple_strtoul (data, &data,10 ); + parsed_port =simple_strtoul (data, &data,10 ); +if (parsed_port >65535 ) +return -1 ; + + *port = parsed_port; *ad_end_p = data;return 0 ;
Signature · 1 line
2.54.0