From patchwork Tue Jun 19 03:16:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 165635 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 E499FB6FFC for ; Tue, 19 Jun 2012 13:17:25 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752886Ab2FSDRT (ORCPT ); Mon, 18 Jun 2012 23:17:19 -0400 Received: from mail.us.es ([193.147.175.20]:53890 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753253Ab2FSDRO (ORCPT ); Mon, 18 Jun 2012 23:17:14 -0400 Received: (qmail 17479 invoked from network); 19 Jun 2012 05:17:13 +0200 Received: from unknown (HELO us.es) (192.168.2.11) by us.es with SMTP; 19 Jun 2012 05:17:13 +0200 Received: (qmail 18998 invoked by uid 507); 19 Jun 2012 03:17:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on antivirus1 X-Spam-Level: X-Spam-Status: No, score=-97.8 required=7.5 tests=BAYES_50,RCVD_IN_PBL, RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from 127.0.0.1 by antivirus1 (envelope-from , uid 501) with qmail-scanner-2.08 (clamdscan: 0.97.4/15056. Clear:RC:1(127.0.0.1):. Processed in 0.046831 secs); 19 Jun 2012 03:17:12 -0000 Received: from unknown (HELO antivirus1) (127.0.0.1) by us.es with SMTP; 19 Jun 2012 03:17:12 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus1 (F-Secure/fsigk_smtp/407/antivirus1); Tue, 19 Jun 2012 05:17:11 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/407/antivirus1) Received: (qmail 3268 invoked from network); 19 Jun 2012 05:18:33 +0200 Received: from 179.116.221.87.dynamic.jazztel.es (HELO localhost.localdomain) (pneira@us.es@87.221.116.179) by us.es with SMTP; 19 Jun 2012 05:18:33 +0200 From: pablo@netfilter.org To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 2/4] netfilter: nf_ct_helper: disable automatic helper re-assignment of different type Date: Tue, 19 Jun 2012 05:16:27 +0200 Message-Id: <1340075789-6196-3-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1340075789-6196-1-git-send-email-pablo@netfilter.org> References: <1340075789-6196-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: Pablo Neira Ayuso This patch modifies __nf_ct_try_assign_helper in a way that invalidates support for the following scenario: 1) attach the helper A for first time when the conntrack is created 2) attach new (different) helper B due to changes the reply tuple caused by NAT eg. port redirection from TCP/21 to TCP/5060 with both FTP and SIP helpers loaded, which seems to be a quite unorthodox scenario. I can provide a more elaborated patch to support this scenario but explicit helper attachment provides a better solution for this since now the use can attach the helpers consistently, without relying on the automatic helper lookup magic. This patch fixes a possible out of bound zeroing of the conntrack helper extension if the helper B uses more memory for its private data than helper A. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c index 2918ec2..c4bc637 100644 --- a/net/netfilter/nf_conntrack_helper.c +++ b/net/netfilter/nf_conntrack_helper.c @@ -229,7 +229,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, goto out; } } else { - memset(help->data, 0, helper->data_len); + /* We only allow helper re-assignment of the same sort since + * we cannot reallocate the helper extension area. + */ + if (help->helper != helper) { + RCU_INIT_POINTER(help->helper, NULL); + goto out; + } } rcu_assign_pointer(help->helper, helper);