Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: ipt_ULOG: fix non-null terminated string in the nf_log path

If nf_log uses ipt_ULOG as logging output, we can deliver non-null
terminated strings to user-space since the maximum length of the
prefix that is passed by nf_log is NF_LOG_PREFIXLEN but pm->prefix
is 32 bytes long (ULOG_PREFIX_LEN).

This is actually happening already from nf_conntrack_tcp if ipt_ULOG
is used, since it is passing strings longer than 32 bytes.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Chen Gang and committed by
Pablo Neira Ayuso
4f36ea6e 2a7851bf

+4 -2
+4 -2
net/ipv4/netfilter/ipt_ULOG.c
··· 231 231 put_unaligned(tv.tv_usec, &pm->timestamp_usec); 232 232 put_unaligned(skb->mark, &pm->mark); 233 233 pm->hook = hooknum; 234 - if (prefix != NULL) 235 - strncpy(pm->prefix, prefix, sizeof(pm->prefix)); 234 + if (prefix != NULL) { 235 + strncpy(pm->prefix, prefix, sizeof(pm->prefix) - 1); 236 + pm->prefix[sizeof(pm->prefix) - 1] = '\0'; 237 + } 236 238 else if (loginfo->prefix[0] != '\0') 237 239 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix)); 238 240 else