Received: by 10.213.65.68 with SMTP id h4csp751337imn; Fri, 6 Apr 2018 08:17:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+5XLpBJA7VyY1Ie+hv8oY+jeDTksKGyo2WDrJJfedrFFebsyXWV455Urjh/gSLsJDlVpeb X-Received: by 2002:a17:902:69ce:: with SMTP id m14-v6mr28199612pln.358.1523027843187; Fri, 06 Apr 2018 08:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523027843; cv=none; d=google.com; s=arc-20160816; b=tPFs55REOa+AAt0ni1pfoSyzKPaWu/HHw8LZXnwNsHNOHMDQA2SYmWLy+KzwbwkQ5l W3oWCOHp4LCFUDSws81AJYiWFjlGM3+zLnWFZvwVRJ2yAj5vmcLHSTeB2lVt3r1c50L+ 7ad7gYqXMsaIdRj/zKNqpoX00ZzVjFExCf9y+G7HOSCrK2V+L+YiobD1arzh9iK07NC7 NKOqCv0zypZWbhjhnGs6gxKE2Ri++jT8TeO0fd9WGdpuGdmiEKDfBSXO+lJoPhz2mZ1U rCxLj6mmgCrXkSMiHS+Ar6lKfPH0OZDQukh/Q6q+46YMfK5nCpgL781IhFWF84fBp6Ry XXRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=6QsDDenkWFmcXZsm1BaU6NiHYNMYyRM9wN7ALl04KeY=; b=Dvifng2p8vUI/S+WsEMKHwaMBfnhR38SzTWovc7UiSF1p30jewT3uBJOOvVpRzpNx4 0TH/lpDIXxF3jnF1/n2OaD1nuDUKooMDQvvbLA0XgU14ZAPym0BY++P521huzKbbpykh 7I/VNAgwcdCPjM0sBs3ZBDboIAQg7opCql9lE+Qfoh8xSdIY9v/ftBtaNTQWbc34xNEE cvRJ1b5HATkWoFs6QdgydLFUFOGT7jmBxdhHHcW8CBonsoNo4U8NrGVz3fY0sQsFhQ9s Ht/Y1I6atNtc4Jm3Nkp2RNjtx/Vb6DCEGNrYNrPhpHCNdk1Jff9gq3KKPPy9H4K7lLgM Xmqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12-v6si8466363pln.298.2018.04.06.08.17.08; Fri, 06 Apr 2018 08:17:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754451AbeDFN2l (ORCPT + 99 others); Fri, 6 Apr 2018 09:28:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55428 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752755AbeDFN2h (ORCPT ); Fri, 6 Apr 2018 09:28:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 005B9BD0; Fri, 6 Apr 2018 13:28:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot+0502b00edac2a0680b61@syzkaller.appspotmail.com, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 3.18 54/93] netfilter: x_tables: add and use xt_check_proc_name Date: Fri, 6 Apr 2018 15:23:23 +0200 Message-Id: <20180406084227.270123514@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084224.918716300@linuxfoundation.org> References: <20180406084224.918716300@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal commit b1d0a5d0cba4597c0394997b2d5fced3e3841b4e upstream. recent and hashlimit both create /proc files, but only check that name is 0 terminated. This can trigger WARN() from procfs when name is "" or "/". Add helper for this and then use it for both. Cc: Eric Dumazet Reported-by: Eric Dumazet Reported-by: Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- include/linux/netfilter/x_tables.h | 2 ++ net/netfilter/x_tables.c | 30 ++++++++++++++++++++++++++++++ net/netfilter/xt_hashlimit.c | 5 +++-- net/netfilter/xt_recent.c | 6 +++--- 4 files changed, 38 insertions(+), 5 deletions(-) --- a/include/linux/netfilter/x_tables.h +++ b/include/linux/netfilter/x_tables.h @@ -247,6 +247,8 @@ unsigned int *xt_alloc_entry_offsets(uns bool xt_find_jump_offset(const unsigned int *offsets, unsigned int target, unsigned int size); +int xt_check_proc_name(const char *name, unsigned int size); + int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto, bool inv_proto); int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto, --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -367,6 +367,36 @@ textify_hooks(char *buf, size_t size, un return buf; } +/** + * xt_check_proc_name - check that name is suitable for /proc file creation + * + * @name: file name candidate + * @size: length of buffer + * + * some x_tables modules wish to create a file in /proc. + * This function makes sure that the name is suitable for this + * purpose, it checks that name is NUL terminated and isn't a 'special' + * name, like "..". + * + * returns negative number on error or 0 if name is useable. + */ +int xt_check_proc_name(const char *name, unsigned int size) +{ + if (name[0] == '\0') + return -EINVAL; + + if (strnlen(name, size) == size) + return -ENAMETOOLONG; + + if (strcmp(name, ".") == 0 || + strcmp(name, "..") == 0 || + strchr(name, '/')) + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL(xt_check_proc_name); + int xt_check_match(struct xt_mtchk_param *par, unsigned int size, u_int8_t proto, bool inv_proto) { --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -668,8 +668,9 @@ static int hashlimit_mt_check(const stru if (info->cfg.gc_interval == 0 || info->cfg.expire == 0) return -EINVAL; - if (info->name[sizeof(info->name)-1] != '\0') - return -EINVAL; + ret = xt_check_proc_name(info->name, sizeof(info->name)); + if (ret) + return ret; if (par->family == NFPROTO_IPV4) { if (info->cfg.srcmask > 32 || info->cfg.dstmask > 32) return -EINVAL; --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -355,9 +355,9 @@ static int recent_mt_check(const struct info->hit_count, ip_pkt_list_tot); return -EINVAL; } - if (info->name[0] == '\0' || - strnlen(info->name, XT_RECENT_NAME_LEN) == XT_RECENT_NAME_LEN) - return -EINVAL; + ret = xt_check_proc_name(info->name, sizeof(info->name)); + if (ret) + return ret; mutex_lock(&recent_mutex); t = recent_table_lookup(recent_net, info->name);