On 2020/5/19 12:44, Tetsuo Handa wrote:
On 2020/05/19 12:31, Xiaoming Ni wrote:
Some boundary (.extra1 .extra2) constants (E.g: neg_one two) in
sysctl.c are used in multiple features. Move these variables to
sysctl_vals to avoid adding duplicate variables when cleaning up
sysctls table.
Signed-off-by: Xiaoming Ni <nixiaoming@xxxxxxxxxx>
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
I feel that it is use of
void *extra1;
void *extra2;
in "struct ctl_table" that requires constant values indirection.
Can't we get rid of sysctl_vals using some "union" like below?
struct ctl_table {
const char *procname; /* Text ID for /proc/sys, or zero */
void *data;
int maxlen;
umode_t mode;
struct ctl_table *child; /* Deprecated */
proc_handler *proc_handler; /* Callback for text formatting */
struct ctl_table_poll *poll;
union {
void *min_max_ptr[2];
int min_max_int[2];
long min_max_long[2];
};
} __randomize_layout;
.
net/decnet/dn_dev.c:
static void dn_dev_sysctl_register(struct net_device *dev, struct
dn_dev_parms *parms)
{
struct dn_dev_sysctl_table *t;
int i;
char path[sizeof("net/decnet/conf/") + IFNAMSIZ];
t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
if (t == NULL)
return;
for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
long offset = (long)t->dn_dev_vars[i].data;
t->dn_dev_vars[i].data = ((char *)parms) + offset;
}
snprintf(path, sizeof(path), "net/decnet/conf/%s",
dev? dev->name : parms->name);
t->dn_dev_vars[0].extra1 = (void *)dev;
t->sysctl_header = register_net_sysctl(&init_net, path, t->dn_dev_vars);
if (t->sysctl_header == NULL)
kfree(t);
else
parms->sysctl = t;
}
A small amount of code is not used as a boundary value when using
extra1. This scenario may not be suitable for renaming to min_max_ptr.
Should we add const to extra1 extra2 ?
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -124,8 +124,8 @@ struct ctl_table {
struct ctl_table *child; /* Deprecated */
proc_handler *proc_handler; /* Callback for text formatting */
struct ctl_table_poll *poll;
- void *extra1;
- void *extra2;
+ const void *extra1;
+ const void *extra2;
} __randomize_layout;
Thanks
Xiaoming Ni