Skip to content

Commit a92b383

Browse files
committed
sysctl: expose proc_dointvec_minmax_sysadmin as API function
Orthogonal to the other sysctl proc functions expose the variant that is checking CAP_SYS_ADMIN on write for consumption in external subsystem's sysctl tables. Signed-off-by: Levente Polyak <[email protected]>
1 parent d8ad413 commit a92b383

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

include/linux/sysctl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
5353
int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
5454
int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
5555
size_t *lenp, loff_t *ppos);
56+
int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
57+
void *buffer, size_t *lenp, loff_t *ppos);
5658
int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
5759
int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
5860
loff_t *);

kernel/sysctl.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,16 +896,34 @@ static int proc_taint(struct ctl_table *table, int write,
896896
return err;
897897
}
898898

899-
#ifdef CONFIG_PRINTK
900-
static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
899+
/**
900+
* proc_dointvec_minmax_sysadmin - read a vector of integers with min/max values
901+
* checking CAP_SYS_ADMIN on write
902+
* @table: the sysctl table
903+
* @write: %TRUE if this is a write to the sysctl file
904+
* @buffer: the user buffer
905+
* @lenp: the size of the user buffer
906+
* @ppos: file position
907+
*
908+
* Reads/writes up to table->maxlen/sizeof(unsigned int) integer
909+
* values from/to the user buffer, treated as an ASCII string.
910+
*
911+
* This routine will ensure the values are within the range specified by
912+
* table->extra1 (min) and table->extra2 (max).
913+
*
914+
* Writing is only allowed when root has CAP_SYS_ADMIN.
915+
*
916+
* Returns 0 on success, -EPERM on permission failure or -EINVAL on write
917+
* when the range check fails.
918+
*/
919+
int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
901920
void *buffer, size_t *lenp, loff_t *ppos)
902921
{
903922
if (write && !capable(CAP_SYS_ADMIN))
904923
return -EPERM;
905924

906925
return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
907926
}
908-
#endif
909927

910928
/**
911929
* struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
@@ -1591,6 +1609,12 @@ int proc_douintvec_minmax(struct ctl_table *table, int write,
15911609
return -ENOSYS;
15921610
}
15931611

1612+
int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1613+
void *buffer, size_t *lenp, loff_t *ppos)
1614+
{
1615+
return -ENOSYS;
1616+
}
1617+
15941618
int proc_dointvec_jiffies(struct ctl_table *table, int write,
15951619
void *buffer, size_t *lenp, loff_t *ppos)
15961620
{
@@ -3464,6 +3488,7 @@ EXPORT_SYMBOL(proc_douintvec);
34643488
EXPORT_SYMBOL(proc_dointvec_jiffies);
34653489
EXPORT_SYMBOL(proc_dointvec_minmax);
34663490
EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3491+
EXPORT_SYMBOL(proc_dointvec_minmax_sysadmin);
34673492
EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
34683493
EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
34693494
EXPORT_SYMBOL(proc_dostring);

0 commit comments

Comments
 (0)