All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net/9p: Return error if we fail to encode protocol data
@ 2010-10-18 14:40 Aneesh Kumar K.V
  2010-10-18 14:40 ` [PATCH 2/2] net/9p: Return error on read with NULL buffer Aneesh Kumar K.V
  0 siblings, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2010-10-18 14:40 UTC (permalink / raw)
  To: v9fs-developer; +Cc: linux-fsdevel, linux-kernel, Aneesh Kumar K.V

We need to return error in case we fail to encode data in protocl buffer.
This patch also return error in case of a failed copy_from_user.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 net/9p/client.c   |    2 ++
 net/9p/protocol.c |    5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/9p/client.c b/net/9p/client.c
index b2b066a..e141e46 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -579,6 +579,8 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
 	va_start(ap, fmt);
 	err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap);
 	va_end(ap);
+	if (err)
+		goto reterr;
 	p9pdu_finalize(req->tc);
 
 	err = c->trans_mod->request(c, req);
diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index 3acd3af..45c15f4 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -122,9 +122,8 @@ static size_t
 pdu_write_u(struct p9_fcall *pdu, const char __user *udata, size_t size)
 {
 	size_t len = MIN(pdu->capacity - pdu->size, size);
-	int err = copy_from_user(&pdu->sdata[pdu->size], udata, len);
-	if (err)
-		printk(KERN_WARNING "pdu_write_u returning: %d\n", err);
+	if (copy_from_user(&pdu->sdata[pdu->size], udata, len))
+		len = 0;
 
 	pdu->size += len;
 	return size - len;
-- 
1.7.1


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

* [PATCH 2/2] net/9p: Return error on read with NULL buffer
  2010-10-18 14:40 [PATCH 1/2] net/9p: Return error if we fail to encode protocol data Aneesh Kumar K.V
@ 2010-10-18 14:40 ` Aneesh Kumar K.V
  2010-10-23 19:59   ` Brad Boyer
  0 siblings, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2010-10-18 14:40 UTC (permalink / raw)
  To: v9fs-developer
  Cc: linux-fsdevel, linux-kernel, Sanchit Garg, Aneesh Kumar K.V

From: Sanchit Garg <sancgarg@linux.vnet.ibm.com>

This patch ensures that a read(fd, NULL, 0 ) returns  EFAULT on a 9p file.

Signed-off-by: Sanchit Garg <sancgarg@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 net/9p/client.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/9p/client.c b/net/9p/client.c
index e141e46..d5344d8 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -1313,6 +1313,11 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 	rsize = fid->iounit;
 	if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
 		rsize = clnt->msize - P9_IOHDRSZ;
+	/*
+	 * A read with NULL user buffer cause EFAULT error
+	 */
+	if (!data && !udata)
+		return -EFAULT;
 
 	if (count < rsize)
 		rsize = count;
@@ -1333,16 +1338,13 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 
 	if (data) {
 		memmove(data, dataptr, count);
-	}
-
-	if (udata) {
+	} else {
 		err = copy_to_user(udata, dataptr, count);
 		if (err) {
 			err = -EFAULT;
 			goto free_and_error;
 		}
 	}
-
 	p9_free_req(clnt, req);
 	return count;
 
-- 
1.7.1


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

* Re: [PATCH 2/2] net/9p: Return error on read with NULL buffer
  2010-10-18 14:40 ` [PATCH 2/2] net/9p: Return error on read with NULL buffer Aneesh Kumar K.V
@ 2010-10-23 19:59   ` Brad Boyer
  2010-10-24 14:32     ` Aneesh Kumar K. V
  0 siblings, 1 reply; 4+ messages in thread
From: Brad Boyer @ 2010-10-23 19:59 UTC (permalink / raw)
  To: Aneesh Kumar K.V
  Cc: v9fs-developer, linux-fsdevel, linux-kernel, Sanchit Garg

On Mon, Oct 18, 2010 at 08:10:53PM +0530, Aneesh Kumar K.V wrote:
> This patch ensures that a read(fd, NULL, 0 ) returns  EFAULT on a 9p file.

Is there some specific reason you want this behavior? I believe the
generic Linux code returns success in this case. I tried this exact
system call with fd being a pty or a file on ext3 and got 0 for both.

	Brad Boyer
	flar@allandria.com


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

* Re: [PATCH 2/2] net/9p: Return error on read with NULL buffer
  2010-10-23 19:59   ` Brad Boyer
@ 2010-10-24 14:32     ` Aneesh Kumar K. V
  0 siblings, 0 replies; 4+ messages in thread
From: Aneesh Kumar K. V @ 2010-10-24 14:32 UTC (permalink / raw)
  To: Brad Boyer; +Cc: v9fs-developer, linux-fsdevel, linux-kernel, Sanchit Garg

On Sat, 23 Oct 2010 12:59:57 -0700, Brad Boyer <flar@allandria.com> wrote:
> On Mon, Oct 18, 2010 at 08:10:53PM +0530, Aneesh Kumar K.V wrote:
> > This patch ensures that a read(fd, NULL, 0 ) returns  EFAULT on a 9p file.
> 
> Is there some specific reason you want this behavior? I believe the
> generic Linux code returns success in this case. I tried this exact
> system call with fd being a pty or a file on ext3 and got 0 for both.

Linux code return 0 in case count == 0;
This is what i find on ext4.

open("a.c", O_RDONLY)                   = 3
read(3, 0, 10)                          = -1 EFAULT (Bad address)

open("a.c", O_RDONLY)                   = 3
read(3, NULL, 0)                        = 0

This patch ensure that we get the behaviour as in case one in case of 9p
file system. But patch broke the behaviour in step 2. So below is the
updated one

commit bd1717e5300ab0bb9aa2df139ffbc5e49f1baeb6
Author: Sanchit Garg <sancgarg@linux.vnet.ibm.com>
Date:   Tue Oct 19 09:17:02 2010 +0530

    net/9p: Return error on read with NULL buffer
    
    This patch ensures that a read(fd, NULL, 10) returns  EFAULT on a 9p file.
    
    Signed-off-by: Sanchit Garg <sancgarg@linux.vnet.ibm.com>
    Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

diff --git a/net/9p/client.c b/net/9p/client.c
index e141e46..dbca5b3 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -1333,16 +1333,13 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 
 	if (data) {
 		memmove(data, dataptr, count);
-	}
-
-	if (udata) {
+	} else {
 		err = copy_to_user(udata, dataptr, count);
 		if (err) {
 			err = -EFAULT;
 			goto free_and_error;
 		}
 	}
-
 	p9_free_req(clnt, req);
 	return count;
 


-aneesh

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

end of thread, other threads:[~2010-10-24 14:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-18 14:40 [PATCH 1/2] net/9p: Return error if we fail to encode protocol data Aneesh Kumar K.V
2010-10-18 14:40 ` [PATCH 2/2] net/9p: Return error on read with NULL buffer Aneesh Kumar K.V
2010-10-23 19:59   ` Brad Boyer
2010-10-24 14:32     ` Aneesh Kumar K. V

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.