netfilter: x_tables: add and use xt_check_proc_name
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. Change-Id: I6772510c4de2697a546204cb0d11df406a17e2a1 Cc: Eric Dumazet <eric.dumazet@gmail.com> Reported-by: Eric Dumazet <eric.dumazet@gmail.com> Reported-by: <syzbot+0502b00edac2a0680b61@syzkaller.appspotmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> [bwh: Backported to 3.16: - xt_hashlimit has only one check function - Adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
This commit is contained in:
parent
2c057e1e72
commit
641d6e007f
|
@ -248,6 +248,8 @@ extern int xt_check_match(struct xt_mtchk_param *,
|
||||||
extern int xt_check_target(struct xt_tgchk_param *,
|
extern int xt_check_target(struct xt_tgchk_param *,
|
||||||
unsigned int size, u_int8_t proto, bool inv_proto);
|
unsigned int size, u_int8_t proto, bool inv_proto);
|
||||||
|
|
||||||
|
int xt_check_proc_name(const char *name, unsigned int size);
|
||||||
|
|
||||||
void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
|
void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
|
||||||
struct xt_counters_info *info, bool compat);
|
struct xt_counters_info *info, bool compat);
|
||||||
|
|
||||||
|
|
|
@ -380,6 +380,36 @@ textify_hooks(char *buf, size_t size, unsigned int mask, uint8_t nfproto)
|
||||||
return buf;
|
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,
|
int xt_check_match(struct xt_mtchk_param *par,
|
||||||
unsigned int size, u_int8_t proto, bool inv_proto)
|
unsigned int size, u_int8_t proto, bool inv_proto)
|
||||||
{
|
{
|
||||||
|
|
|
@ -664,8 +664,9 @@ static int hashlimit_mt_check(const struct xt_mtchk_param *par)
|
||||||
|
|
||||||
if (info->cfg.gc_interval == 0 || info->cfg.expire == 0)
|
if (info->cfg.gc_interval == 0 || info->cfg.expire == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (info->name[sizeof(info->name)-1] != '\0')
|
ret = xt_check_proc_name(info->name, sizeof(info->name));
|
||||||
return -EINVAL;
|
if (ret)
|
||||||
|
return ret;
|
||||||
if (par->family == NFPROTO_IPV4) {
|
if (par->family == NFPROTO_IPV4) {
|
||||||
if (info->cfg.srcmask > 32 || info->cfg.dstmask > 32)
|
if (info->cfg.srcmask > 32 || info->cfg.dstmask > 32)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -358,9 +358,9 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
|
||||||
info->hit_count, ip_pkt_list_tot);
|
info->hit_count, ip_pkt_list_tot);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (info->name[0] == '\0' ||
|
ret = xt_check_proc_name(info->name, sizeof(info->name));
|
||||||
strnlen(info->name, XT_RECENT_NAME_LEN) == XT_RECENT_NAME_LEN)
|
if (ret)
|
||||||
return -EINVAL;
|
return ret;
|
||||||
|
|
||||||
mutex_lock(&recent_mutex);
|
mutex_lock(&recent_mutex);
|
||||||
t = recent_table_lookup(recent_net, info->name);
|
t = recent_table_lookup(recent_net, info->name);
|
||||||
|
|
Loading…
Reference in New Issue