linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] sunrpc: Fix reserved port range calculation and possible panic
@ 2016-07-08 21:35 Frank Sorenson
  2016-07-08 21:35 ` [PATCH 1/3] sunrpc: Fix reserved port range calculation Frank Sorenson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Frank Sorenson @ 2016-07-08 21:35 UTC (permalink / raw)
  To: linux-nfs

The range calculation for choosing the random reserved port will panic
with divide-by-zero when min_resvport == max_resvport, a range of one
port, not zero.

In addition, the sysctl and kernel module parameters only limit the
min_resvport and max_resvport values to the entire range of allowed
ports, so the min and max may become inverted, with max_resvport
set to a value lower than min_resvport.

These patches address both issues by correcting the port range
calculation and setting the min_resvport/max_resvport limits
to be dependent on each other.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>


[PATCH 1/3] sunrpc: Fix reserved port range calculation
[PATCH 2/3] sunrpc: Prevent resvport min/max inversion via sysctl
[PATCH 3/3] sunrpc: Prevent resvport min/max inversion via sysfs and

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] sunrpc: Fix reserved port range calculation
  2016-07-08 21:35 [PATCH 0/3] sunrpc: Fix reserved port range calculation and possible panic Frank Sorenson
@ 2016-07-08 21:35 ` Frank Sorenson
  2016-07-08 21:35 ` [PATCH 2/3] sunrpc: Prevent resvport min/max inversion via sysctl Frank Sorenson
  2016-07-08 21:35 ` [PATCH 3/3] sunrpc: Prevent resvport min/max inversion via sysfs and module parameter Frank Sorenson
  2 siblings, 0 replies; 4+ messages in thread
From: Frank Sorenson @ 2016-07-08 21:35 UTC (permalink / raw)
  To: linux-nfs

The range calculation for choosing the random reserved port will panic
with divide-by-zero when min_resvport == max_resvport, a range of one
port, not zero.

Fix the reserved port range calculation by adding one to the difference.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 net/sunrpc/xprtsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 7e2b2fa..1adda71 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -1714,7 +1714,7 @@ static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
 
 static unsigned short xs_get_random_port(void)
 {
-	unsigned short range = xprt_max_resvport - xprt_min_resvport;
+	unsigned short range = xprt_max_resvport - xprt_min_resvport + 1;
 	unsigned short rand = (unsigned short) prandom_u32() % range;
 	return rand + xprt_min_resvport;
 }
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] sunrpc: Prevent resvport min/max inversion via sysctl
  2016-07-08 21:35 [PATCH 0/3] sunrpc: Fix reserved port range calculation and possible panic Frank Sorenson
  2016-07-08 21:35 ` [PATCH 1/3] sunrpc: Fix reserved port range calculation Frank Sorenson
@ 2016-07-08 21:35 ` Frank Sorenson
  2016-07-08 21:35 ` [PATCH 3/3] sunrpc: Prevent resvport min/max inversion via sysfs and module parameter Frank Sorenson
  2 siblings, 0 replies; 4+ messages in thread
From: Frank Sorenson @ 2016-07-08 21:35 UTC (permalink / raw)
  To: linux-nfs

The current min/max resvport settings are independently limited
by the entire range of allowed ports, so max_resvport can be
set to a port lower than min_resvport.

Prevent inversion of min/max values when set through sysctl by
setting the limits dependent on each other.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 net/sunrpc/xprtsock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 1adda71..2674309 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -124,7 +124,7 @@ static struct ctl_table xs_tunables_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= &xprt_min_resvport_limit,
-		.extra2		= &xprt_max_resvport_limit
+		.extra2		= &xprt_max_resvport
 	},
 	{
 		.procname	= "max_resvport",
@@ -132,7 +132,7 @@ static struct ctl_table xs_tunables_table[] = {
 		.maxlen		= sizeof(unsigned int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= &xprt_min_resvport_limit,
+		.extra1		= &xprt_min_resvport,
 		.extra2		= &xprt_max_resvport_limit
 	},
 	{
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] sunrpc: Prevent resvport min/max inversion via sysfs and module parameter
  2016-07-08 21:35 [PATCH 0/3] sunrpc: Fix reserved port range calculation and possible panic Frank Sorenson
  2016-07-08 21:35 ` [PATCH 1/3] sunrpc: Fix reserved port range calculation Frank Sorenson
  2016-07-08 21:35 ` [PATCH 2/3] sunrpc: Prevent resvport min/max inversion via sysctl Frank Sorenson
@ 2016-07-08 21:35 ` Frank Sorenson
  2 siblings, 0 replies; 4+ messages in thread
From: Frank Sorenson @ 2016-07-08 21:35 UTC (permalink / raw)
  To: linux-nfs

The current min/max resvport settings are independently limited
by the entire range of allowed ports, so max_resvport can be
set to a port lower than min_resvport.

Prevent inversion of min/max values when set through sysfs and
module parameter by setting the limits dependent on each other.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 net/sunrpc/xprtsock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 2674309..83e6f33 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -3153,8 +3153,12 @@ static int param_set_uint_minmax(const char *val,
 
 static int param_set_portnr(const char *val, const struct kernel_param *kp)
 {
-	return param_set_uint_minmax(val, kp,
+	if (kp->arg == &xprt_min_resvport)
+		return param_set_uint_minmax(val, kp,
 			RPC_MIN_RESVPORT,
+			xprt_max_resvport);
+	return param_set_uint_minmax(val, kp,
+			xprt_min_resvport,
 			RPC_MAX_RESVPORT);
 }
 
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-08 21:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-08 21:35 [PATCH 0/3] sunrpc: Fix reserved port range calculation and possible panic Frank Sorenson
2016-07-08 21:35 ` [PATCH 1/3] sunrpc: Fix reserved port range calculation Frank Sorenson
2016-07-08 21:35 ` [PATCH 2/3] sunrpc: Prevent resvport min/max inversion via sysctl Frank Sorenson
2016-07-08 21:35 ` [PATCH 3/3] sunrpc: Prevent resvport min/max inversion via sysfs and module parameter Frank Sorenson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).