svcrdma: endian bug in send_write_chunks()
Subsystems (5)
PATCH 1/1 svcrdma: endian bug in send_write_chunks()
Sparse complains because arg_ch->rs_length is declared as network endian but we're treating it as CPU endian.
net/sunrpc/xprtrdma/svc_rdma_sendto.c +2 -2
@@ -409,7 +409,7 @@ static int send_write_chunks(struct svcxprt_rdma *xprt,u64 rs_offset; arg_ch = &arg_ary->wc_array[chunk_no].wc_target; - write_len =min (xfer_len, arg_ch->rs_length); + write_len =min (xfer_len,ntohl (arg_ch->rs_length));/* Prepare the response chunk given the length actually * written */
@@ -481,7 +481,7 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt, chunk_no++) {u64 rs_offset; ch = &arg_ary->wc_array[chunk_no].wc_target; - write_len =min (xfer_len, ch->rs_length); + write_len =min (xfer_len,ntohl (ch->rs_length));/* Prepare the reply chunk given the length actually * written */
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.
This looks like it would actually change behavior on a little endian architecture, so how did this work before?
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)
and
...rs_length = htonl(...)
but only see one declaration for a field named rs_length.
So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
?
--b.
Quoted 25 lines
Signed-off-by Dan Carpenter <[email protected]>net/sunrpc/xprtrdma/svc_rdma_sendto.c +2
-2@@ -409,7 +409,7 @@ static int send_write_chunks(struct svcxprt_rdma *xprt,u64 rs_offset; arg_ch = &arg_ary->wc_array[chunk_no].wc_target; - write_len =min (xfer_len, arg_ch->rs_length); + write_len =min (xfer_len,ntohl (arg_ch->rs_length));/* Prepare the response chunk given the length actually * written */ @@ -481,7 +481,7 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt, chunk_no++) {u64 rs_offset; ch = &arg_ary->wc_array[chunk_no].wc_target; - write_len =min (xfer_len, ch->rs_length); + write_len =min (xfer_len,ntohl (ch->rs_length));/* Prepare the reply chunk given the length actually * written */
Quoted 13 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
Quoted 7 lines
...rs_length = htonl(...)but only see one declaration for a field named
rs_length.So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
It looks to me as if rs_handle and rs_offset are being similarly abused. Basically, we need a serious clean up in svc_rdma_marshall.c to separate out those variables that are in XDR-encoded form and those that are not.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 15 lines · Trond Myklebust
Quoted 14 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
...rs_length = htonl(...)
Quoted 9 lines
Quoted 5 lines
but only see one declaration for a field named
rs_length.So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
It looks to me as if
rs_handleandrs_offsetare being similarly abused. Basically, we need a serious clean up insvc_rdma_marshall.cto separate out those variables that are in XDR-encoded form and those that are not.
The abuse is taking place because the marshal/unmarshall is being done in-place and it seemed wasteful at the time to add a chunk of memory to preserve the aesthetic. A union would 'work', but you still wouldn't 'know' whether the data was NBO or not by where it was -- which seems like the intent of the __beXX in the first place.
Tom
A message that is not in the archive (sent off-list or not yet received): 4F0F3380.4000406-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org
Quoted 25 lines · Tom Tucker
Quoted 15 lines · Trond Myklebust
Quoted 14 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
...rs_length = htonl(...)Quoted 9 lines
Quoted 5 lines
but only see one declaration for a field named
rs_length.So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
It looks to me as if
rs_handleandrs_offsetare being similarly abused. Basically, we need a serious clean up insvc_rdma_marshall.cto separate out those variables that are in XDR-encoded form and those that are not.
Quoted 5 lines
The abuse is taking place because the marshal/unmarshall is being done in-place and it seemed wasteful at the time to add a chunk of memory to preserve the aesthetic. A union would 'work', but you still wouldn't 'know' whether the data was NBO or not by where it was -- which seems like the intent of the
__beXXin the first place.
These are not variables that are used in hundreds of different places:
why not just do the conversion from big-endian to cpu-endian when you actually need to use them?
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
A message that is not in the archive (sent off-list or not yet received): 1326396510.6198.12.camel-SyLVLa/[email protected]
Quoted 25 lines · Trond Myklebust
Quoted 24 lines · Tom Tucker
Quoted 23 lines · Trond Myklebust
Quoted 11 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
Quoted 7 lines
...rs_length = htonl(...)but only see one declaration for a field named
rs_length.So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
It looks to me as if
rs_handleandrs_offsetare being similarly abused. Basically, we need a serious clean up insvc_rdma_marshall.cto separate out those variables that are in XDR-encoded form and those that are not.
Quoted 8 lines
Quoted 5 lines
The abuse is taking place because the marshal/unmarshall is being done in-place and it seemed wasteful at the time to add a chunk of memory to preserve the aesthetic. A union would 'work', but you still wouldn't 'know' whether the data was NBO or not by where it was -- which seems like the intent of the
__beXXin the first place.These are not variables that are used in hundreds of different places:
why not just do the conversion from big-endian to cpu-endian when you actually need to use them?
That would work fine actually. At the time, I was trying to put all that marshalling logic in that one file and reuse the already present client-side header file that copies that stuff when it decodes it.
I'll dig around a little bit and see what might be the simplest way to clean this up.
Tom
A message that is not in the archive (sent off-list or not yet received): 1326395759.6198.7.camel-SyLVLa/[email protected]
Quoted 18 lines · Trond Myklebust
Quoted 17 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
...rs_length = htonl(...)but only see one declaration for a field named
rs_length.
Quoted 7 lines
Quoted 3 lines
So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
It looks to me as if
rs_handleandrs_offsetare being similarly abused. Basically, we need a serious clean up insvc_rdma_marshall.cto separate out those variables that are in XDR-encoded form and those that are not.
(Here everybody takes one step back and pretends to be engrossed in some other thread.)
--b.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 13 lines · J. Bruce Fields
Quoted 2 lines · Dan Carpenter
Sparse complains because
arg_ch->rs_lengthis declared as network endian but we're treating it as CPU endian.This looks like it would actually change behavior on a little endian architecture, so how did this work before?
Quoted 1 line
From some quick grepping, I see assignments both of the form
...rs_length = ntohl(...)and
Quoted 7 lines
...rs_length = htonl(...)but only see one declaration for a field named
rs_length.So my best guess would be that the code is ugly but working as is, and needs cleanup by someone who knows how this field was intended to be used.
Gar. Sorry for that. I knew it changed the behavior, and I tried to see how the original code worked, but I didn't read carefully enough. I'll try be more careful next time.
Thanks for catching that.
regards,
dan carpenter