From patchwork Tue Jul 2 14:50:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 256432 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E67852C0090 for ; Wed, 3 Jul 2013 00:51:35 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752974Ab3GBOvd (ORCPT ); Tue, 2 Jul 2013 10:51:33 -0400 Received: from mail.us.es ([193.147.175.20]:43830 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752945Ab3GBOvd (ORCPT ); Tue, 2 Jul 2013 10:51:33 -0400 Received: (qmail 27431 invoked from network); 2 Jul 2013 16:51:31 +0200 Received: from unknown (HELO us.es) (192.168.2.13) by us.es with SMTP; 2 Jul 2013 16:51:31 +0200 Received: (qmail 14644 invoked by uid 507); 2 Jul 2013 14:51:31 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus3 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.97.8/17448. spamassassin: 3.3.2. Clear:RC:1(127.0.0.1):SA:0(-98.2/7.5):. Processed in 3.934281 secs); 02 Jul 2013 14:51:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on antivirus3 X-Spam-Level: X-Spam-Status: No, score=-98.2 required=7.5 tests=BAYES_50,RCVD_IN_PBL, RDNS_NONE,USER_IN_WHITELIST autolearn=disabled version=3.3.2 X-Envelope-From: pablo@netfilter.org Received: from unknown (HELO antivirus3) (127.0.0.1) by us.es with SMTP; 2 Jul 2013 14:51:27 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus3 (F-Secure/fsigk_smtp/410/antivirus3); Tue, 02 Jul 2013 16:51:27 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/410/antivirus3) Received: (qmail 29266 invoked from network); 2 Jul 2013 16:51:25 +0200 Received: from unknown (HELO localhost.localdomain) (pneira@us.es@77.208.93.96) by us.es with SMTP; 2 Jul 2013 16:51:25 +0200 From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, stable@vger.kernel.org Subject: [PATCH -stable-3.9 02/15] netfilter: ipt_ULOG: fix non-null terminated string in the nf_log path Date: Tue, 2 Jul 2013 16:50:52 +0200 Message-Id: <1372776665-6795-2-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372776665-6795-1-git-send-email-pablo@netfilter.org> References: <1372776665-6795-1-git-send-email-pablo@netfilter.org> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Chen Gang 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 Signed-off-by: Pablo Neira Ayuso --- Cherry-pick: 4f36ea6eed2081340c7a7aa98c73187ecfccebff net/ipv4/netfilter/ipt_ULOG.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c index 7d168dc..3202b7d 100644 --- a/net/ipv4/netfilter/ipt_ULOG.c +++ b/net/ipv4/netfilter/ipt_ULOG.c @@ -215,8 +215,10 @@ static void ipt_ulog_packet(unsigned int hooknum, 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