Skip to contentSkip to conversation

net/sunrpc: Fix return value from proc_do_xprt()

PATCH In review Alex Dewar 2 participants 4 messages Oct 24, 2020 – Nov 7, 2020

Subsystems (4)
lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 net/sunrpc: Fix return value from proc_do_xprt()

Commit c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports") attempted to add error checking for the call to memory_read_from_buffer(), however its return value was assigned to a size_t variable, so any negative values would be lost in the cast. Fix this.

Addresses-Coverity-ID: 1498033: Control flow issues (NO_EFFECT)

Fixes c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports")
---
 net/sunrpc/sysctl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/sysctl.c +5 -2
index a18b36b5422d..c95a2b84dd95 100644
@@ -62,6 +62,7 @@ rpc_unregister_sysctl(void)
 static int proc_do_xprt(struct ctl_table *table, int write,
 			void *buffer, size_t *lenp, loff_t *ppos)
 {
+	ssize_t bytes_read;
 	char tmpbuf[256];
 	size_t len;
 
@@ -70,12 +71,14 @@ static int proc_do_xprt(struct ctl_table *table, int write,
 		return 0;
 	}
 	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
-	*lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
+	bytes_read = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
 
-	if (*lenp < 0) {
+	if (bytes_read < 0) {
 		*lenp = 0;
 		return -EINVAL;
 	}
+
+	*lenp = bytes_read;
 	return 0;
 }
 
Signature · 1 line
2.29.1
#1 lore raw

Whoops, got 3 independent patches for this and overlooked this one. See
https://lore.kernel.org/linux-nfs/[email protected]/T/#t

--b.

Quoted 44 lines · Alex Dewar

Commit c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports") attempted to add error checking for the call to memory_read_from_buffer(), however its return value was assigned to a size_t variable, so any negative values would be lost in the cast. Fix this.

Addresses-Coverity-ID: 1498033: Control flow issues (NO_EFFECT)

Fixes c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports")
---
 net/sunrpc/sysctl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/sysctl.c +5 -2
index a18b36b5422d..c95a2b84dd95 100644
@@ -62,6 +62,7 @@ rpc_unregister_sysctl(void)
 static int proc_do_xprt(struct ctl_table *table, int write,
 			void *buffer, size_t *lenp, loff_t *ppos)
 {
+	ssize_t bytes_read;
 	char tmpbuf[256];
 	size_t len;
 
@@ -70,12 +71,14 @@ static int proc_do_xprt(struct ctl_table *table, int write,
 		return 0;
 	}
 	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
-	*lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
+	bytes_read = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
 
-	if (*lenp < 0) {
+	if (bytes_read < 0) {
 		*lenp = 0;
 		return -EINVAL;
 	}
+
+	*lenp = bytes_read;
 	return 0;
 }
 
Signature · 1 line
2.29.1
author
#2 lore raw
Quoted 4 lines · J. Bruce Fields

Whoops, got 3 independent patches for this and overlooked this one. See
https://lore.kernel.org/linux-nfs/[email protected]/T/#t

--b.

That looks like a cleaner fix. Thanks for looking anyhow and sorry for the noise!

Quoted 46 lines · Alex Dewar
Quoted 44 lines

Commit c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports") attempted to add error checking for the call to memory_read_from_buffer(), however its return value was assigned to a size_t variable, so any negative values would be lost in the cast. Fix this.

Addresses-Coverity-ID: 1498033: Control flow issues (NO_EFFECT)

Fixes c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports")
---
 net/sunrpc/sysctl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/sysctl.c +5 -2
index a18b36b5422d..c95a2b84dd95 100644
@@ -62,6 +62,7 @@ rpc_unregister_sysctl(void)
 static int proc_do_xprt(struct ctl_table *table, int write,
 			void *buffer, size_t *lenp, loff_t *ppos)
 {
+	ssize_t bytes_read;
 	char tmpbuf[256];
 	size_t len;
 
@@ -70,12 +71,14 @@ static int proc_do_xprt(struct ctl_table *table, int write,
 		return 0;
 	}
 	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
-	*lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
+	bytes_read = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
 
-	if (*lenp < 0) {
+	if (bytes_read < 0) {
 		*lenp = 0;
 		return -EINVAL;
 	}
+
+	*lenp = bytes_read;
 	return 0;
 }
 
Signature · 1 line
2.29.1
#3 lore raw
Quoted 8 lines · Alex Dewar
Quoted 4 lines · J. Bruce Fields

Whoops, got 3 independent patches for this and overlooked this one. See
https://lore.kernel.org/linux-nfs/[email protected]/T/#t

--b.

That looks like a cleaner fix. Thanks for looking anyhow and sorry for the noise!

Not noise, all these efforts are appreciated.---b.

Quoted 47 lines
Quoted 47 lines · Alex Dewar
Quoted 44 lines

Commit c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports") attempted to add error checking for the call to memory_read_from_buffer(), however its return value was assigned to a size_t variable, so any negative values would be lost in the cast. Fix this.

Addresses-Coverity-ID: 1498033: Control flow issues (NO_EFFECT)

Fixes c09f56b8f68d ("net/sunrpc: Fix return value for sysctl sunrpc.transports")
---
 net/sunrpc/sysctl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/sysctl.c +5 -2
index a18b36b5422d..c95a2b84dd95 100644
@@ -62,6 +62,7 @@ rpc_unregister_sysctl(void)
 static int proc_do_xprt(struct ctl_table *table, int write,
 			void *buffer, size_t *lenp, loff_t *ppos)
 {
+	ssize_t bytes_read;
 	char tmpbuf[256];
 	size_t len;
 
@@ -70,12 +71,14 @@ static int proc_do_xprt(struct ctl_table *table, int write,
 		return 0;
 	}
 	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
-	*lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
+	bytes_read = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
 
-	if (*lenp < 0) {
+	if (bytes_read < 0) {
 		*lenp = 0;
 		return -EINVAL;
 	}
+
+	*lenp = bytes_read;
 	return 0;
 }
 
Signature · 1 line
2.29.1