Skip to content

Commit a25bab9

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Fix segfault when writing to sysfs elp_interval
The per hardif sysfs file "batman_adv/elp_interval" is using the generic functions to store/show uint values. The helper __batadv_store_uint_attr requires the softif net_device as parameter to print the resulting change as info text when the users writes to this file. It uses the helper function batadv_info to add it at the same time to the kernel ring buffer and to the batman-adv debug log (when CONFIG_BATMAN_ADV_DEBUG is enabled). The function batadv_info requires as first parameter the batman-adv softif net_device. This parameter is then used to find the private buffer which contains the debug log for this batman-adv interface. But batadv_store_throughput_override used as first argument the slave net_device. This slave device doesn't have the batadv_priv private data which is access by batadv_info. Writing to this file with CONFIG_BATMAN_ADV_DEBUG enabled can either lead to a segfault or to memory corruption. Fixes: 0744ff8 ("batman-adv: Add hard_iface specific sysfs wrapper macros for UINT") Signed-off-by: Sven Eckelmann <[email protected]> Acked-by: Marek Lindner <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent b9fd14c commit a25bab9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

net/batman-adv/sysfs.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ ssize_t batadv_store_##_name(struct kobject *kobj, \
188188
\
189189
return __batadv_store_uint_attr(buff, count, _min, _max, \
190190
_post_func, attr, \
191-
&bat_priv->_var, net_dev); \
191+
&bat_priv->_var, net_dev, \
192+
NULL); \
192193
}
193194

194195
#define BATADV_ATTR_SIF_SHOW_UINT(_name, _var) \
@@ -262,7 +263,9 @@ ssize_t batadv_store_##_name(struct kobject *kobj, \
262263
\
263264
length = __batadv_store_uint_attr(buff, count, _min, _max, \
264265
_post_func, attr, \
265-
&hard_iface->_var, net_dev); \
266+
&hard_iface->_var, \
267+
hard_iface->soft_iface, \
268+
net_dev); \
266269
\
267270
batadv_hardif_put(hard_iface); \
268271
return length; \
@@ -356,10 +359,12 @@ __batadv_store_bool_attr(char *buff, size_t count,
356359

357360
static int batadv_store_uint_attr(const char *buff, size_t count,
358361
struct net_device *net_dev,
362+
struct net_device *slave_dev,
359363
const char *attr_name,
360364
unsigned int min, unsigned int max,
361365
atomic_t *attr)
362366
{
367+
char ifname[IFNAMSIZ + 3] = "";
363368
unsigned long uint_val;
364369
int ret;
365370

@@ -385,8 +390,11 @@ static int batadv_store_uint_attr(const char *buff, size_t count,
385390
if (atomic_read(attr) == uint_val)
386391
return count;
387392

388-
batadv_info(net_dev, "%s: Changing from: %i to: %lu\n",
389-
attr_name, atomic_read(attr), uint_val);
393+
if (slave_dev)
394+
snprintf(ifname, sizeof(ifname), "%s: ", slave_dev->name);
395+
396+
batadv_info(net_dev, "%s: %sChanging from: %i to: %lu\n",
397+
attr_name, ifname, atomic_read(attr), uint_val);
390398

391399
atomic_set(attr, uint_val);
392400
return count;
@@ -397,12 +405,13 @@ static ssize_t __batadv_store_uint_attr(const char *buff, size_t count,
397405
void (*post_func)(struct net_device *),
398406
const struct attribute *attr,
399407
atomic_t *attr_store,
400-
struct net_device *net_dev)
408+
struct net_device *net_dev,
409+
struct net_device *slave_dev)
401410
{
402411
int ret;
403412

404-
ret = batadv_store_uint_attr(buff, count, net_dev, attr->name, min, max,
405-
attr_store);
413+
ret = batadv_store_uint_attr(buff, count, net_dev, slave_dev,
414+
attr->name, min, max, attr_store);
406415
if (post_func && ret)
407416
post_func(net_dev);
408417

@@ -571,7 +580,7 @@ static ssize_t batadv_store_gw_sel_class(struct kobject *kobj,
571580
return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
572581
batadv_post_gw_reselect, attr,
573582
&bat_priv->gw.sel_class,
574-
bat_priv->soft_iface);
583+
bat_priv->soft_iface, NULL);
575584
}
576585

577586
static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,

0 commit comments

Comments
 (0)