Skip to content

Commit e209fee

Browse files
Akihiro Sudadavem330
authored andcommitted
net/ipv4: ping_group_range: allow GID from 2147483648 to 4294967294
With this commit, all the GIDs ("0 4294967294") can be written to the "net.ipv4.ping_group_range" sysctl. Note that 4294967295 (0xffffffff) is an invalid GID (see gid_valid() in include/linux/uidgid.h), and an attempt to register this number will cause -EINVAL. Prior to this commit, only up to GID 2147483647 could be covered. Documentation/networking/ip-sysctl.rst had "0 4294967295" as an example value, but this example was wrong and causing -EINVAL. Fixes: c319b4d ("net: ipv4: add IPPROTO_ICMP socket kind") Co-developed-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Akihiro Suda <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5a59a58 commit e209fee

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,8 @@ ping_group_range - 2 INTEGERS
13521352
Restrict ICMP_PROTO datagram sockets to users in the group range.
13531353
The default is "1 0", meaning, that nobody (not even root) may
13541354
create ping sockets. Setting it to "100 100" would grant permissions
1355-
to the single group. "0 4294967295" would enable it for the world, "100
1356-
4294967295" would enable it for the users, but not daemons.
1355+
to the single group. "0 4294967294" would enable it for the world, "100
1356+
4294967294" would enable it for the users, but not daemons.
13571357

13581358
tcp_early_demux - BOOLEAN
13591359
Enable early demux for established TCP sockets.

include/net/ping.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
#define PING_HTABLE_SIZE 64
1717
#define PING_HTABLE_MASK (PING_HTABLE_SIZE-1)
1818

19-
/*
20-
* gid_t is either uint or ushort. We want to pass it to
21-
* proc_dointvec_minmax(), so it must not be larger than MAX_INT
22-
*/
23-
#define GID_T_MAX (((gid_t)~0U) >> 1)
19+
#define GID_T_MAX (((gid_t)~0U) - 1)
2420

2521
/* Compatibility glue so we can support IPv6 when it's compiled as a module */
2622
struct pingv6_ops {

net/ipv4/sysctl_net_ipv4.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static int ip_ttl_min = 1;
3434
static int ip_ttl_max = 255;
3535
static int tcp_syn_retries_min = 1;
3636
static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
37-
static int ip_ping_group_range_min[] = { 0, 0 };
38-
static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
37+
static unsigned long ip_ping_group_range_min[] = { 0, 0 };
38+
static unsigned long ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
3939
static u32 u32_max_div_HZ = UINT_MAX / HZ;
4040
static int one_day_secs = 24 * 3600;
4141
static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
@@ -165,7 +165,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
165165
{
166166
struct user_namespace *user_ns = current_user_ns();
167167
int ret;
168-
gid_t urange[2];
168+
unsigned long urange[2];
169169
kgid_t low, high;
170170
struct ctl_table tmp = {
171171
.data = &urange,
@@ -178,7 +178,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
178178
inet_get_ping_group_range_table(table, &low, &high);
179179
urange[0] = from_kgid_munged(user_ns, low);
180180
urange[1] = from_kgid_munged(user_ns, high);
181-
ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
181+
ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
182182

183183
if (write && ret == 0) {
184184
low = make_kgid(user_ns, urange[0]);

0 commit comments

Comments
 (0)