Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7280142imu; Wed, 14 Nov 2018 14:47:02 -0800 (PST) X-Google-Smtp-Source: AJdET5e7pBFVn2XFrVf4Iu06juSI83gGZd+OafoOTdW0Ldf4/2PHmZJ8Q2VC+Fna7e8aMtC6PM2G X-Received: by 2002:a17:902:50ec:: with SMTP id c41-v6mr3675742plj.176.1542235622698; Wed, 14 Nov 2018 14:47:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235622; cv=none; d=google.com; s=arc-20160816; b=Z8/nCFPKtjQjyuWDBk0sHi+5wuBpLTLIIvcUpizjcF7c+ROGt/3+NoG1ktgmMT1hGQ PXx4nIvNv62Hp73BUq5v1UpLbNblMhQWpbkBApoYXSiSdOd5Bmg4bBaPtAAxUyhyWVik 8eqycKi7VH3NJ92x2GGvKZaWJXeB2kI8vSvT2HuSZbaS+idBa3/7UheXFSJlE+raCZQs HatJMLQhGI4FS8H10j4xqgk1wghsaiJWqT1WSw2ypy4UcMb5OujUuEG197+8549JJAJP 1WNRUknQ2DIJGF5yDybHNv0OPX4SYaMP9ZqLfVjw+2nBqJsN/CSB4LWHnBDrb3yEmsc3 CbAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ye/9EejqFzfA/hSVUnwlIEyDAH2uXTV+3VB11ZYMczk=; b=TeP2dD3M0fJ5QrSr3HcjnakKjGzCJBlJZht/cAtA63yLbsoXiYRWp5GuRZknpih1ND 7q60Rb10PjbF2vNo00ejh1PoV6B4JxBPJcPq8ua/N2vFPUwEWMppF/c+Gr5/FXvv3lby GUfH9ziuCdJt6s9HrC9jM/yM1hRYeOUITs6qkrg+HOOUC2isFAtj4xz9OHcfWGijPKcM zLgLywfXZ0pv1hl8qPsINznJtmbw8uu9EhoCAlvDZI+AAMEWWIse8ZjEba0pRkP0zUQc 76zxHHFjO4cOl9Dc0OcEVsM3LOVNd+Np5KI6rL6ftkR4O5YvzacvnL8XN8djgm5YTXNY 9pbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cFaTiqPr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si24852553pgl.595.2018.11.14.14.46.48; Wed, 14 Nov 2018 14:47:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=cFaTiqPr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729039AbeKOIuI (ORCPT + 99 others); Thu, 15 Nov 2018 03:50:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:34392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728371AbeKOI1Q (ORCPT ); Thu, 15 Nov 2018 03:27:16 -0500 Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 514DF22511; Wed, 14 Nov 2018 22:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542234133; bh=+MKdJKOpLvla1wJwnzIL8imnFfohNKRmpDA6j49/qgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFaTiqPr7a8meEMl0M/uzQYjeA/s3nTHC7hrPg8EvTGGNWWfBcstTemsb2kB8pd5W XrEwfOQmgLrAn3+VtIPdcsMkrjh+IW9/T/qqJSpTyOFZL7GvNbmH2Ri/WxzxyCzsbX ytma7gv+zlC260n8ZBEcyv8DtdVT1C7AvlQ89wmM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Taehee Yoo , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH AUTOSEL 4.19 21/73] netfilter: xt_IDLETIMER: add sysfs filename checking routine Date: Wed, 14 Nov 2018 17:21:15 -0500 Message-Id: <20181114222207.98701-21-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114222207.98701-1-sashal@kernel.org> References: <20181114222207.98701-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taehee Yoo [ Upstream commit 54451f60c8fa061af9051a53be9786393947367c ] When IDLETIMER rule is added, sysfs file is created under /sys/class/xt_idletimer/timers/ But some label name shouldn't be used. ".", "..", "power", "uevent", "subsystem", etc... So that sysfs filename checking routine is needed. test commands: %iptables -I INPUT -j IDLETIMER --timeout 1 --label "power" splat looks like: [95765.423132] sysfs: cannot create duplicate filename '/devices/virtual/xt_idletimer/timers/power' [95765.433418] CPU: 0 PID: 8446 Comm: iptables Not tainted 4.19.0-rc6+ #20 [95765.449755] Call Trace: [95765.449755] dump_stack+0xc9/0x16b [95765.449755] ? show_regs_print_info+0x5/0x5 [95765.449755] sysfs_warn_dup+0x74/0x90 [95765.449755] sysfs_add_file_mode_ns+0x352/0x500 [95765.449755] sysfs_create_file_ns+0x179/0x270 [95765.449755] ? sysfs_add_file_mode_ns+0x500/0x500 [95765.449755] ? idletimer_tg_checkentry+0x3e5/0xb1b [xt_IDLETIMER] [95765.449755] ? rcu_read_lock_sched_held+0x114/0x130 [95765.449755] ? __kmalloc_track_caller+0x211/0x2b0 [95765.449755] ? memcpy+0x34/0x50 [95765.449755] idletimer_tg_checkentry+0x4e2/0xb1b [xt_IDLETIMER] [ ... ] Fixes: 0902b469bd25 ("netfilter: xtables: idletimer target implementation") Signed-off-by: Taehee Yoo Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/xt_IDLETIMER.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c index 5ee859193783..25453a16385e 100644 --- a/net/netfilter/xt_IDLETIMER.c +++ b/net/netfilter/xt_IDLETIMER.c @@ -116,6 +116,22 @@ static void idletimer_tg_expired(struct timer_list *t) schedule_work(&timer->work); } +static int idletimer_check_sysfs_name(const char *name, unsigned int size) +{ + int ret; + + ret = xt_check_proc_name(name, size); + if (ret < 0) + return ret; + + if (!strcmp(name, "power") || + !strcmp(name, "subsystem") || + !strcmp(name, "uevent")) + return -EINVAL; + + return 0; +} + static int idletimer_tg_create(struct idletimer_tg_info *info) { int ret; @@ -126,6 +142,10 @@ static int idletimer_tg_create(struct idletimer_tg_info *info) goto out; } + ret = idletimer_check_sysfs_name(info->label, sizeof(info->label)); + if (ret < 0) + goto out_free_timer; + sysfs_attr_init(&info->timer->attr.attr); info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL); if (!info->timer->attr.attr.name) { -- 2.17.1