Skip to content

Commit 54451f6

Browse files
TaeheeYooummakynes
authored andcommitted
netfilter: xt_IDLETIMER: add sysfs filename checking routine
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+ thesofproject#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: 0902b46 ("netfilter: xtables: idletimer target implementation") Signed-off-by: Taehee Yoo <ap420073@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 17b8b74 commit 54451f6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

net/netfilter/xt_IDLETIMER.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ static void idletimer_tg_expired(struct timer_list *t)
114114
schedule_work(&timer->work);
115115
}
116116

117+
static int idletimer_check_sysfs_name(const char *name, unsigned int size)
118+
{
119+
int ret;
120+
121+
ret = xt_check_proc_name(name, size);
122+
if (ret < 0)
123+
return ret;
124+
125+
if (!strcmp(name, "power") ||
126+
!strcmp(name, "subsystem") ||
127+
!strcmp(name, "uevent"))
128+
return -EINVAL;
129+
130+
return 0;
131+
}
132+
117133
static int idletimer_tg_create(struct idletimer_tg_info *info)
118134
{
119135
int ret;
@@ -124,6 +140,10 @@ static int idletimer_tg_create(struct idletimer_tg_info *info)
124140
goto out;
125141
}
126142

143+
ret = idletimer_check_sysfs_name(info->label, sizeof(info->label));
144+
if (ret < 0)
145+
goto out_free_timer;
146+
127147
sysfs_attr_init(&info->timer->attr.attr);
128148
info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
129149
if (!info->timer->attr.attr.name) {

0 commit comments

Comments
 (0)