]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
netfilter: ipt_ULOG: fix non-null terminated string in the nf_log path
authorChen Gang <gang.chen@asianux.com>
Thu, 23 May 2013 01:50:46 +0000 (01:50 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 23 May 2013 12:25:40 +0000 (14:25 +0200)
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>
net/ipv4/netfilter/ipt_ULOG.c

index cf08218ddbcf6799464139b681239137de2d9142..ff4b781b1056e59937d44e9d751b6acf299d7a60 100644 (file)
@@ -231,8 +231,10 @@ static void ipt_ulog_packet(struct net *net,
        put_unaligned(tv.tv_usec, &pm->timestamp_usec);
        put_unaligned(skb->mark, &pm->mark);
        pm->hook = hooknum;
-       if (prefix != NULL)
-               strncpy(pm->prefix, prefix, sizeof(pm->prefix));
+       if (prefix != NULL) {
+               strncpy(pm->prefix, prefix, sizeof(pm->prefix) - 1);
+               pm->prefix[sizeof(pm->prefix) - 1] = '\0';
+       }
        else if (loginfo->prefix[0] != '\0')
                strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
        else