Skip to content

Commit 4f36ea6

Browse files
Chen Gangummakynes
authored andcommitted
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>
1 parent 2a7851b commit 4f36ea6

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎net/ipv4/netfilter/ipt_ULOG.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ static void ipt_ulog_packet(struct net *net,
231231
put_unaligned(tv.tv_usec, &pm->timestamp_usec);
232232
put_unaligned(skb->mark, &pm->mark);
233233
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+
}
236238
else if (loginfo->prefix[0] != '\0')
237239
strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
238240
else

0 commit comments

Comments
 (0)