Patch "netfilter: x_tables: add and use xt_check_proc_name" has been added to the 4.15-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
netfilter: x_tables: add and use xt_check_proc_name
to the 4.15-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
netfilter-x_tables-add-and-use-xt_check_proc_name.patch
and it can be found in the queue-4.15 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
b1d0a5d0cba4597c0394997b2d5fced3e3841b4eMon Sep 17 00:00:00 2001
From: Florian Westphal <[email protected]>
Date: Sat, 10 Mar 2018 01:15:45 +0100
Subject: netfilter: x_tables: add and use xt_check_proc_name
From: Florian Westphal <[email protected]>
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.
--- include/linux/netfilter/x_tables.h | 2 ++ net/netfilter/x_tables.c | 30 ++++++++++++++++++++++++++++++ net/netfilter/xt_hashlimit.c | 16 ++++++++++------ net/netfilter/xt_recent.c | 6 +++--- 4 files changed, 45 insertions(+), 9 deletions(-)
include/linux/netfilter/x_tables.h +2 -0
@@ -285,6 +285,8 @@ unsigned int *xt_alloc_entry_offsets(unsbool 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,
net/netfilter/x_tables.c +30 -0
@@ -423,6 +423,36 @@ textify_hooks(char *buf, size_t size, unreturn 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) {
net/netfilter/xt_hashlimit.c +10 -6
@@ -915,8 +915,9 @@ static int hashlimit_mt_check_v1(const sstruct hashlimit_cfg3 cfg = {};int ret; -if (info->name[sizeof (info->name) -1 ] !='\0' ) -return -EINVAL ; + ret =xt_check_proc_name (info->name,sizeof (info->name)); +if (ret) +return ret; ret =cfg_copy (&cfg, (void *)&info->cfg,1 );
@@ -933,8 +934,9 @@ static int hashlimit_mt_check_v2(const sstruct hashlimit_cfg3 cfg = {};int ret; -if (info->name[sizeof (info->name) -1 ] !='\0' ) -return -EINVAL ; + ret =xt_check_proc_name (info->name,sizeof (info->name)); +if (ret) +return ret; ret =cfg_copy (&cfg, (void *)&info->cfg,2 );
@@ -948,9 +950,11 @@ static int hashlimit_mt_check_v2(const sstatic int hashlimit_mt_check (const struct xt_mtchk_param *par) {struct xt_hashlimit_mtinfo3 *info = par->matchinfo; +int ret; -if (info->name[sizeof (info->name) -1 ] !='\0' ) -return -EINVAL ; + ret =xt_check_proc_name (info->name,sizeof (info->name)); +if (ret) +return ret;return hashlimit_mt_check_common (par, &info->hinfo, &info->cfg, info->name,3 );
net/netfilter/xt_recent.c +3 -3
@@ -361,9 +361,9 @@ static int recent_mt_check(const struct info->hit_count, XT_RECENT_MAX_NSTAMPS - 1);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;if (ip_pkt_list_tot && info->hit_count < ip_pkt_list_tot) nstamp_mask =roundup_pow_of_two (ip_pkt_list_tot) -1 ;
Patches currently in stable-queue which might be from [email protected] are
queue-4.15/netfilter-x_tables-add-and-use-xt_check_proc_name.patch queue-4.15/xfrm_user-uncoditionally-validate-esn-replay-attribute-struct.patch queue-4.15/netfilter-x_tables-make-allocation-less-aggressive.patch queue-4.15/netfilter-bridge-ebt_among-add-more-missing-match-size-checks.patch queue-4.15/netfilter-drop-template-ct-when-conntrack-is-skipped.patch