From patchwork Fri Jul 1 09:45:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chleroy X-Patchwork-Id: 642908 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 3rgsBH2HMpz9sR8 for ; Fri, 1 Jul 2016 19:51:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752240AbcGAJvN (ORCPT ); Fri, 1 Jul 2016 05:51:13 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:5480 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523AbcGAJvL (ORCPT ); Fri, 1 Jul 2016 05:51:11 -0400 X-Greylist: delayed 326 seconds by postgrey-1.27 at vger.kernel.org; Fri, 01 Jul 2016 05:51:10 EDT Received: from localhost (unknown [192.168.12.234]) by localhost (Postfix) with ESMTP id 3rgs3T3JmRz9ttRW; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id VRVXjaSQlU73; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 3rgs3T2QYZz9ttRV; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B9D1F8B898; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id e67JIyV6_Ch6; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) Received: from PO10863.localdomain (po10863.idsi0.si.c-s.fr [172.25.231.6]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9690C8B892; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) Received: by localhost.localdomain (Postfix, from userid 0) id 2A8AA1A23A2; Fri, 1 Jul 2016 11:45:41 +0200 (CEST) From: chleroy Subject: [PATCH] netfilter: nf_conntrack_sip: CSeq 0 is a valid CSeq To: Pablo Neira Ayuso , Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <20160701094541.2A8AA1A23A2@localhost.localdomain> Date: Fri, 1 Jul 2016 11:45:41 +0200 (CEST) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Do not drop packet when CSeq is 0 as 0 is also a valid value for CSeq. In order to do so, we replace obsolete simple_strtoul() which returns 0 on error by kstrtouint(). As kstrtouint() requires a NULL terminated string, we need to use a temporary buffer Signed-off-by: Christophe Leroy --- net/netfilter/nf_conntrack_sip.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c index f72ba55..e770477 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c @@ -1368,6 +1368,7 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff, struct nf_conn *ct = nf_ct_get(skb, &ctinfo); unsigned int matchoff, matchlen, matchend; unsigned int code, cseq, i; + char buf[21]; if (*datalen < strlen("SIP/2.0 200")) return NF_ACCEPT; @@ -1382,8 +1383,13 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff, nf_ct_helper_log(skb, ct, "cannot parse cseq"); return NF_DROP; } - cseq = simple_strtoul(*dptr + matchoff, NULL, 10); - if (!cseq) { + if (matchlen > sizeof(buf) - 1) { + nf_ct_helper_log(skb, ct, "cannot parse cseq (too big)"); + return NF_DROP; + } + memcpy(buf, *dptr + matchoff, matchlen); + buf[matchlen] = 0; + if (kstrtouint(buf, 10, &cseq)) { nf_ct_helper_log(skb, ct, "cannot get cseq"); return NF_DROP; } @@ -1432,6 +1438,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff, for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) { const struct sip_handler *handler; + char buf[21]; handler = &sip_handlers[i]; if (handler->request == NULL) @@ -1445,8 +1452,13 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff, nf_ct_helper_log(skb, ct, "cannot parse cseq"); return NF_DROP; } - cseq = simple_strtoul(*dptr + matchoff, NULL, 10); - if (!cseq) { + if (matchlen > sizeof(buf) - 1) { + nf_ct_helper_log(skb, ct, "cannot parse cseq(too big)"); + return NF_DROP; + } + memcpy(buf, *dptr + matchoff, matchlen); + buf[matchlen] = 0; + if (kstrtouint(buf, 10, &cseq)) { nf_ct_helper_log(skb, ct, "cannot get cseq"); return NF_DROP; }