diff mbox

[V2] xdrstdio_create buffers do not output encoded values on ppc

Message ID 20180629184256.20532-1-steved@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Steve Dickson June 29, 2018, 6:42 p.m. UTC
From: Daniel Sands <dnsands@sandia.gov>

The cause is that the xdr_putlong uses a long to store the
converted value, then passes it to fwrite as a byte buffer.
Only the first 4 bytes are written, which is okay for a LE
system after byteswapping, but writes all zeroes on BE systems.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738

Signed-off-by: Steve Dickson <steved@redhat.com>
---
v2: Added bounds checking
    Changed from unsigned to signed

 src/xdr_stdio.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Chuck Lever III June 29, 2018, 7:19 p.m. UTC | #1
> On Jun 29, 2018, at 2:42 PM, Steve Dickson <steved@redhat.com> wrote:
> 
> From: Daniel Sands <dnsands@sandia.gov>
> 
> The cause is that the xdr_putlong uses a long to store the
> converted value, then passes it to fwrite as a byte buffer.
> Only the first 4 bytes are written, which is okay for a LE
> system after byteswapping, but writes all zeroes on BE systems.
> 
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738
> 
> Signed-off-by: Steve Dickson <steved@redhat.com>
> ---
> v2: Added bounds checking
>    Changed from unsigned to signed
> 
> src/xdr_stdio.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
> index 4410262..b902acd 100644
> --- a/src/xdr_stdio.c
> +++ b/src/xdr_stdio.c
> @@ -103,10 +103,12 @@ xdrstdio_getlong(xdrs, lp)
> 	XDR *xdrs;
> 	long *lp;
> {
> +	int32_t mycopy;
> 
> -	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
> +	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
> 		return (FALSE);
> -	*lp = (long)ntohl((u_int32_t)*lp);
> +
> +	*lp = (long)ntohl(mycopy);
> 	return (TRUE);
> }
> 
> @@ -115,8 +117,14 @@ xdrstdio_putlong(xdrs, lp)
> 	XDR *xdrs;
> 	const long *lp;
> {
> -	long mycopy = (long)htonl((u_int32_t)*lp);
> +	int32_t mycopy;
> +
> +#if defined(_LP64)

I don't find an _LP64 macro defined within libtirpc or the C libraries
on my RHEL 7 system. The test really should look something like this:

#if __BITS_PER_LONG == 64

though I'm sure that's not right either.


> +	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))
> +		return (FALSE);
> +#endif
> 
> +	mycopy = (int32_t)htonl((int32_t)*lp);
> 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
> 		return (FALSE);
> 	return (TRUE);
> -- 
> 2.17.1
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Libtirpc-devel mailing list
> Libtirpc-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libtirpc-devel

--
Chuck Lever



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Trond Myklebust June 29, 2018, 7:29 p.m. UTC | #2
T24gRnJpLCAyMDE4LTA2LTI5IGF0IDE0OjQyIC0wNDAwLCBTdGV2ZSBEaWNrc29uIHdyb3RlOg0K
PiBGcm9tOiBEYW5pZWwgU2FuZHMgPGRuc2FuZHNAc2FuZGlhLmdvdj4NCj4gDQo+IFRoZSBjYXVz
ZSBpcyB0aGF0IHRoZSB4ZHJfcHV0bG9uZyB1c2VzIGEgbG9uZyB0byBzdG9yZSB0aGUNCj4gY29u
dmVydGVkIHZhbHVlLCB0aGVuIHBhc3NlcyBpdCB0byBmd3JpdGUgYXMgYSBieXRlIGJ1ZmZlci4N
Cj4gT25seSB0aGUgZmlyc3QgNCBieXRlcyBhcmUgd3JpdHRlbiwgd2hpY2ggaXMgb2the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zMl90KSpscCkpDQoJCXJldHVybiAoRkFMU0UpOw0K
DQouLi5vciBzb21ldGhpbmcgdWdsaWVyIGxpa2UNCg0KCWlmICgqbHAgPiBVSU5UMzJfTUFYIHx8
ICpscCA8IElOVDMyX01JTikNCgkJcmV0dXJuIChGQUxTRSk7DQoNCj4gKyNlbmRpZg0KPiAgDQo+
ICsJbXljb3B5ID0gKGludDMyX3QpaHRvbmwoKGludDMyX3QpKmxwKTsNCj4gIAlpZiAoZndyaXRl
KCZteWNvcHksIHNpemVvZihpbnQzMl90KSwgMSwgKEZJTEUgKil4ZHJzLQ0KPiA+eF9wcml2YXRl
KSAhPSAxKQ0KPiAgCQlyZXR1cm4gKEZBTFNFKTsNCj4gIAlyZXR1cm4gKFRSVUUpOw0KLS0gDQpU
cm9uZCBNeWtsZWJ1c3QNCkNUTywgSGFtbWVyc3BhY2UgSW5jDQo0MzAwIEVsIENhbWlubyBSZWFs
LCBTdWl0ZSAxMDUNCkxvcyBBbHRvcywgQ0EgOTQwMjINCnd3dy5oYW1tZXIuc3BhY2UNCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chuck Lever III June 29, 2018, 7:33 p.m. UTC | #3
> On Jun 29, 2018, at 3:29 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
> 
> On Fri, 2018-06-29 at 14:42 -0400, Steve Dickson wrote:
>> From: Daniel Sands <dnsands@sandia.gov>
>> 
>> The cause is that the xdr_putlong uses a long to store the
>> converted value, then passes it to fwrite as a byte buffer.
>> Only the first 4 bytes are written, which is okay for a LE
>> system after byteswapping, but writes all zeroes on BE systems.
>> 
>> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738
>> 
>> Signed-off-by: Steve Dickson <steved@redhat.com>
>> ---
>> v2: Added bounds checking
>>    Changed from unsigned to signed
>> 
>> src/xdr_stdio.c | 14 +++++++++++---
>> 1 file changed, 11 insertions(+), 3 deletions(-)
>> 
>> diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
>> index 4410262..b902acd 100644
>> --- a/src/xdr_stdio.c
>> +++ b/src/xdr_stdio.c
>> @@ -103,10 +103,12 @@ xdrstdio_getlong(xdrs, lp)
>> 	XDR *xdrs;
>> 	long *lp;
>> {
>> +	int32_t mycopy;
>> 
>> -	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private)
>> != 1)
>> +	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>> x_private) != 1)
>> 		return (FALSE);
>> -	*lp = (long)ntohl((u_int32_t)*lp);
>> +
>> +	*lp = (long)ntohl(mycopy);
>> 	return (TRUE);
>> }
>> 
>> @@ -115,8 +117,14 @@ xdrstdio_putlong(xdrs, lp)
>> 	XDR *xdrs;
>> 	const long *lp;
>> {
>> -	long mycopy = (long)htonl((u_int32_t)*lp);
>> +	int32_t mycopy;
>> +
>> +#if defined(_LP64)
>> +	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))
>> +		return (FALSE);
> 
> The will work just fine if your cast is:
> 	int a;
> 
> 	lp = (long)a;
> 
> ...but it won't do the right thing for
> 
> 	unsigned int b = UINT32_MAX;
> 
> 	lp = (long)b;	/* set lp to UINT32_MAX */

mycopy is an int32_t now. Does that help?


> Since there us no dedicated xdrstdio_putulong() to use for unsigned
> integers, we need the check to work for both cases.
> For that reason, I think the above check either has to be:
> 
> 	if (*lp == (long)((u_int32_t)*lp))
> 		return (FALSE);
> 
> ...or something uglier like
> 
> 	if (*lp > UINT32_MAX || *lp < INT32_MIN)
> 		return (FALSE);
> 
>> +#endif
>> 
>> +	mycopy = (int32_t)htonl((int32_t)*lp);
>> 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>> x_private) != 1)
>> 		return (FALSE);
>> 	return (TRUE);
> -- 
> Trond Myklebust
> CTO, Hammerspace Inc
> 4300 El Camino Real, Suite 105
> Los Altos, CA 94022
> www.hammer.space
> 
> N‹§ēæėrļ›yúčšØbēXŽķĮ§vØ^–)Þš{.nĮ+‰·ĨŠ{ąû"žØ^n‡rĄöĶzˁëh™Ļč­Ú&ĒøŪGŦéhŪ(­éšŽŠÝĒj"úķm§ĸïęäzđޖŠāþfĢĒ·hšˆ§~ˆm

--
Chuck Lever



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Trond Myklebust June 29, 2018, 7:48 p.m. UTC | #4
On Fri, 2018-06-29 at 15:33 -0400, Chuck Lever wrote:
> > On Jun 29, 2018, at 3:29 PM, Trond Myklebust <trondmy@hammerspace.c

> > om> wrote:

> > 

> > On Fri, 2018-06-29 at 14:42 -0400, Steve Dickson wrote:

> > > From: Daniel Sands <dnsands@sandia.gov>

> > > 

> > > The cause is that the xdr_putlong uses a long to store the

> > > converted value, then passes it to fwrite as a byte buffer.

> > > Only the first 4 bytes are written, which is okay for a LE

> > > system after byteswapping, but writes all zeroes on BE systems.

> > > 

> > > Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738

> > > 

> > > Signed-off-by: Steve Dickson <steved@redhat.com>

> > > ---

> > > v2: Added bounds checking

> > >    Changed from unsigned to signed

> > > 

> > > src/xdr_stdio.c | 14 +++++++++++---

> > > 1 file changed, 11 insertions(+), 3 deletions(-)

> > > 

> > > diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c

> > > index 4410262..b902acd 100644

> > > --- a/src/xdr_stdio.c

> > > +++ b/src/xdr_stdio.c

> > > @@ -103,10 +103,12 @@ xdrstdio_getlong(xdrs, lp)

> > > 	XDR *xdrs;

> > > 	long *lp;

> > > {

> > > +	int32_t mycopy;

> > > 

> > > -	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs-

> > > >x_private)

> > > != 1)

> > > +	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-

> > > > x_private) != 1)

> > > 

> > > 		return (FALSE);

> > > -	*lp = (long)ntohl((u_int32_t)*lp);

> > > +

> > > +	*lp = (long)ntohl(mycopy);

> > > 	return (TRUE);

> > > }

> > > 

> > > @@ -115,8 +117,14 @@ xdrstdio_putlong(xdrs, lp)

> > > 	XDR *xdrs;

> > > 	const long *lp;

> > > {

> > > -	long mycopy = (long)htonl((u_int32_t)*lp);

> > > +	int32_t mycopy;

> > > +

> > > +#if defined(_LP64)

> > > +	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))

> > > +		return (FALSE);

> > 

> > The will work just fine if your cast is:

> > 	int a;

> > 

> > 	lp = (long)a;

> > 

> > ...but it won't do the right thing for

> > 

> > 	unsigned int b = UINT32_MAX;

> > 

> > 	lp = (long)b;	/* set lp to UINT32_MAX */

> 

> mycopy is an int32_t now. Does that help?


Not really. 'mycopy' isn't involved in the check above, and *lp ==
UINT32_MAX should in either case get cast to the same 32-bit bit
pattern whether mycopy is an int32_t or a u_int32_t.

It's when you try to cast back from 'mycopy' to a long type that the
two can end up differing (an int32_t might get sign extended).

> 

> > Since there us no dedicated xdrstdio_putulong() to use for unsigned

> > integers, we need the check to work for both cases.

> > For that reason, I think the above check either has to be:

> > 

> > 	if (*lp == (long)((u_int32_t)*lp))

> > 		return (FALSE);

> > 

> > ...or something uglier like

> > 

> > 	if (*lp > UINT32_MAX || *lp < INT32_MIN)

> > 		return (FALSE);

> > 

> > > +#endif

> > > 

> > > +	mycopy = (int32_t)htonl((int32_t)*lp);

> > > 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-

> > > > x_private) != 1)

> > > 

> > > 		return (FALSE);

> > > 	return (TRUE);

> > 

> > -- 

> > Trond Myklebust

> > CTO, Hammerspace Inc

> > 4300 El Camino Real, Suite 105

> > Los Altos, CA 94022

> > www.hammer.space

> > 

> > N‹§ēæėrļ›yúčšØbēXŽķĮ§vØ^–)Þš{.nĮ+‰·ĨŠ{ąû"žØ^n‡rĄöĶzˁëh™Ļč­Ú&ĒøŪ

> > GŦéhŪ(­éšŽŠÝĒj"úķm§ĸïęäzđÞ–ŠāþfĢĒ·hšˆ§~ˆm

> 

> --

> Chuck Lever

> 

> 

> 

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com
Chuck Lever III June 29, 2018, 8:02 p.m. UTC | #5
> On Jun 29, 2018, at 3:48 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
> 
> On Fri, 2018-06-29 at 15:33 -0400, Chuck Lever wrote:
>>> On Jun 29, 2018, at 3:29 PM, Trond Myklebust <trondmy@hammerspace.c
>>> om> wrote:
>>> 
>>> On Fri, 2018-06-29 at 14:42 -0400, Steve Dickson wrote:
>>>> From: Daniel Sands <dnsands@sandia.gov>
>>>> 
>>>> The cause is that the xdr_putlong uses a long to store the
>>>> converted value, then passes it to fwrite as a byte buffer.
>>>> Only the first 4 bytes are written, which is okay for a LE
>>>> system after byteswapping, but writes all zeroes on BE systems.
>>>> 
>>>> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738
>>>> 
>>>> Signed-off-by: Steve Dickson <steved@redhat.com>
>>>> ---
>>>> v2: Added bounds checking
>>>>   Changed from unsigned to signed
>>>> 
>>>> src/xdr_stdio.c | 14 +++++++++++---
>>>> 1 file changed, 11 insertions(+), 3 deletions(-)
>>>> 
>>>> diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
>>>> index 4410262..b902acd 100644
>>>> --- a/src/xdr_stdio.c
>>>> +++ b/src/xdr_stdio.c
>>>> @@ -103,10 +103,12 @@ xdrstdio_getlong(xdrs, lp)
>>>> 	XDR *xdrs;
>>>> 	long *lp;
>>>> {
>>>> +	int32_t mycopy;
>>>> 
>>>> -	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>> x_private)
>>>> != 1)
>>>> +	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>> x_private) != 1)
>>>> 
>>>> 		return (FALSE);
>>>> -	*lp = (long)ntohl((u_int32_t)*lp);
>>>> +
>>>> +	*lp = (long)ntohl(mycopy);
>>>> 	return (TRUE);
>>>> }
>>>> 
>>>> @@ -115,8 +117,14 @@ xdrstdio_putlong(xdrs, lp)
>>>> 	XDR *xdrs;
>>>> 	const long *lp;
>>>> {
>>>> -	long mycopy = (long)htonl((u_int32_t)*lp);
>>>> +	int32_t mycopy;
>>>> +
>>>> +#if defined(_LP64)
>>>> +	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))
>>>> +		return (FALSE);
>>> 
>>> The will work just fine if your cast is:
>>> 	int a;
>>> 
>>> 	lp = (long)a;
>>> 
>>> ...but it won't do the right thing for
>>> 
>>> 	unsigned int b = UINT32_MAX;
>>> 
>>> 	lp = (long)b;	/* set lp to UINT32_MAX */
>> 
>> mycopy is an int32_t now. Does that help?
> 
> Not really. 'mycopy' isn't involved in the check above, and *lp ==
> UINT32_MAX should in either case get cast to the same 32-bit bit
> pattern whether mycopy is an int32_t or a u_int32_t.

> It's when you try to cast back from 'mycopy' to a long type that the
> two can end up differing (an int32_t might get sign extended).

AFAICT we are casting *lp to an int32_t in this function. mycopy
is not being cast to a long here.

Do you mean xdrstdio_GETlong needs further protection? Could be,
there is a cast of an int32_t to a long there.

I agree that we should vet xdrstdio_getlong and xdrstdio_putlong for
sign-extension issues very carefully.


>>> Since there us no dedicated xdrstdio_putulong() to use for unsigned
>>> integers, we need the check to work for both cases.
>>> For that reason, I think the above check either has to be:
>>> 
>>> 	if (*lp == (long)((u_int32_t)*lp))
>>> 		return (FALSE);
>>> 
>>> ...or something uglier like
>>> 
>>> 	if (*lp > UINT32_MAX || *lp < INT32_MIN)
>>> 		return (FALSE);
>>> 
>>>> +#endif
>>>> 
>>>> +	mycopy = (int32_t)htonl((int32_t)*lp);
>>>> 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>> x_private) != 1)
>>>> 
>>>> 		return (FALSE);
>>>> 	return (TRUE);
>>> 
>>> -- 
>>> Trond Myklebust
>>> CTO, Hammerspace Inc
>>> 4300 El Camino Real, Suite 105
>>> Los Altos, CA 94022
>>> www.hammer.space
>>> 
>>> N‹§ēæėrļ›yúčšØbēXŽķĮ§vØ^–)Þš{.nĮ+‰·ĨŠ{ąû"žØ^n‡rĄöĶzˁëh™Ļč­Ú&ĒøŪ
>>> GŦéhŪ(­éšŽŠÝĒj"úķm§ĸïęäzđÞ–ŠāþfĢĒ·hšˆ§~ˆm
>> 
>> --
>> Chuck Lever
>> 
>> 
>> 
> -- 
> Trond Myklebust
> Linux NFS client maintainer, Hammerspace
> trond.myklebust@hammerspace.com

--
Chuck Lever



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Trond Myklebust June 29, 2018, 8:15 p.m. UTC | #6
T24gRnJpLCAyMDE4LTA2LTI5IGF0IDE2OjAyIC0wNDAwLCBDaHVjayBMZXZlciB3cm90ZToNCj4g
PiBPbiBKdW4gMjksIDIwMTgsIGF0IDM6NDggUE0sIFRyb25kIE15a2xlYnVzdCA8dHJvbmRteUBo
YW1tZXJzcGFjZS5jDQo+ID4gb20+IHdyb3RlOg0KPiA+IA0KPiA+IE9uIEZyaSwgMjAxOC0wNi0y
OSBhdCAxNTozMyAtMDQwMCwgQ2h1Y2sgTGV2ZXIgd3JvdGU6DQo+ID4gPiA+IE9uIEp1biAyOSwg
MjAxOCwgYXQgMzoyOSBQTSwgVHJvbmQgTXlrbGVidXN0IDx0cm9uZG15QGhhbW1lcnNwYQ0KPiA+
ID4gPiBjZS5jDQo+ID4gPiA+IG9tPiB3cm90ZToNCj4gPiA+ID4gDQo+ID4gPiA+IE9uIEZyaSwg
MjAxOC0wNi0yOSBhdCAxNDo0MiAtMDQwMCwgU3RldmUgRGlja3NvbiB3cm90ZToNCj4gPiA+ID4g
PiBGcm9tOiBEYW5pZWwgU2FuZHMgPGRuc2FuZHNAc2FuZGlhLmdvdj4NCj4gPiA+ID4gPiANCj4g
PiA+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this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chuck Lever III June 29, 2018, 8:40 p.m. UTC | #7
> On Jun 29, 2018, at 4:15 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
> 
> On Fri, 2018-06-29 at 16:02 -0400, Chuck Lever wrote:
>>> On Jun 29, 2018, at 3:48 PM, Trond Myklebust <trondmy@hammerspace.c
>>> om> wrote:
>>> 
>>> On Fri, 2018-06-29 at 15:33 -0400, Chuck Lever wrote:
>>>>> On Jun 29, 2018, at 3:29 PM, Trond Myklebust <trondmy@hammerspa
>>>>> ce.c
>>>>> om> wrote:
>>>>> 
>>>>> On Fri, 2018-06-29 at 14:42 -0400, Steve Dickson wrote:
>>>>>> From: Daniel Sands <dnsands@sandia.gov>
>>>>>> 
>>>>>> The cause is that the xdr_putlong uses a long to store the
>>>>>> converted value, then passes it to fwrite as a byte buffer.
>>>>>> Only the first 4 bytes are written, which is okay for a LE
>>>>>> system after byteswapping, but writes all zeroes on BE
>>>>>> systems.
>>>>>> 
>>>>>> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1261738
>>>>>> 
>>>>>> Signed-off-by: Steve Dickson <steved@redhat.com>
>>>>>> ---
>>>>>> v2: Added bounds checking
>>>>>>  Changed from unsigned to signed
>>>>>> 
>>>>>> src/xdr_stdio.c | 14 +++++++++++---
>>>>>> 1 file changed, 11 insertions(+), 3 deletions(-)
>>>>>> 
>>>>>> diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
>>>>>> index 4410262..b902acd 100644
>>>>>> --- a/src/xdr_stdio.c
>>>>>> +++ b/src/xdr_stdio.c
>>>>>> @@ -103,10 +103,12 @@ xdrstdio_getlong(xdrs, lp)
>>>>>> 	XDR *xdrs;
>>>>>> 	long *lp;
>>>>>> {
>>>>>> +	int32_t mycopy;
>>>>>> 
>>>>>> -	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>>>> x_private)
>>>>>> 
>>>>>> != 1)
>>>>>> +	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>>>> x_private) != 1)
>>>>>> 
>>>>>> 		return (FALSE);
>>>>>> -	*lp = (long)ntohl((u_int32_t)*lp);
>>>>>> +
>>>>>> +	*lp = (long)ntohl(mycopy);
>>>>>> 	return (TRUE);
>>>>>> }
>>>>>> 
>>>>>> @@ -115,8 +117,14 @@ xdrstdio_putlong(xdrs, lp)
>>>>>> 	XDR *xdrs;
>>>>>> 	const long *lp;
>>>>>> {
>>>>>> -	long mycopy = (long)htonl((u_int32_t)*lp);
>>>>>> +	int32_t mycopy;
>>>>>> +
>>>>>> +#if defined(_LP64)
>>>>>> +	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))
>>>>>> +		return (FALSE);
>>>>> 
>>>>> The will work just fine if your cast is:
>>>>> 	int a;
>>>>> 
>>>>> 	lp = (long)a;
>>>>> 
>>>>> ...but it won't do the right thing for
>>>>> 
>>>>> 	unsigned int b = UINT32_MAX;
>>>>> 
>>>>> 	lp = (long)b;	/* set lp to UINT32_MAX */
>>>> 
>>>> mycopy is an int32_t now. Does that help?
>>> 
>>> Not really. 'mycopy' isn't involved in the check above, and *lp ==
>>> UINT32_MAX should in either case get cast to the same 32-bit bit
>>> pattern whether mycopy is an int32_t or a u_int32_t.
>>> It's when you try to cast back from 'mycopy' to a long type that
>>> the
>>> two can end up differing (an int32_t might get sign extended).
>> 
>> AFAICT we are casting *lp to an int32_t in this function. mycopy
>> is not being cast to a long here.
>> 
>> Do you mean xdrstdio_GETlong needs further protection? Could be,
>> there is a cast of an int32_t to a long there.
>> 
>> I agree that we should vet xdrstdio_getlong and xdrstdio_putlong for
>> sign-extension issues very carefully.
>> 
> 
> The worry for xdrstdio_putlong() should be how we handle the truncation
> when going from (long)-> big endian (int32_t/u_int32_t). We don't want
> to silently lose information.

To put it in terms of an API contract:

If the value in *lp cannot be expressed in 32 bits, xdrstdio_putlong
returns FALSE.


> AFAICS, when casting from a 'long' type, whether 'mycopy' is signed or
> unsigned doesn't really matter when considering what ends up getting
> encoded, as long as it is of size 32-bits. The exception would be if
> sizeof(long) < 4, but libtirpc is broken for that case anyway...
> 
>>>>> Since there us no dedicated xdrstdio_putulong() to use for
>>>>> unsigned
>>>>> integers, we need the check to work for both cases.
>>>>> For that reason, I think the above check either has to be:
>>>>> 
>>>>> 	if (*lp == (long)((u_int32_t)*lp))
>>>>> 		return (FALSE);
>>>>> 
>>>>> ...or something uglier like
>>>>> 
>>>>> 	if (*lp > UINT32_MAX || *lp < INT32_MIN)
>>>>> 		return (FALSE);

On 32 bit systems, long ranges between INT32_MIN and INT32_MAX.
The more narrow range seems to me to be the most portable, as it
guarantees that this API works for exactly the same set of values on
both 32- and 64-bit systems.

Thus I would prefer to exclude the range between INT32_MAX and
UINT32_MAX.


>>>>>> +#endif
>>>>>> 
>>>>>> +	mycopy = (int32_t)htonl((int32_t)*lp);
>>>>>> 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs-
>>>>>>> x_private) != 1)
>>>>>> 
>>>>>> 		return (FALSE);
>>>>>> 	return (TRUE);
>>>>> 
>>>>> -- 
>>>>> Trond Myklebust
>>>>> CTO, Hammerspace Inc
>>>>> 4300 El Camino Real, Suite 105
>>>>> Los Altos, CA 94022
>>>>> www.hammer.space
>>>>> 
>>>>> N‹§ēæėrļ›yúčšØbēXŽķĮ§vØ^–)Þš{.nĮ+‰·ĨŠ{ąû"žØ^n‡rĄöĶzˁëh™Ļč­Ú&
>>>>> ĒøŪ
>>>>> GŦéhŪ(­éšŽŠÝĒj"úķm§ĸïęäzđÞ–ŠāþfĢĒ·hšˆ§~ˆm
>>>> 
>>>> --
>>>> Chuck Lever
>>>> 
>>>> 
>>>> 
>>> 
>>> -- 
>>> Trond Myklebust
>>> Linux NFS client maintainer, Hammerspace
>>> trond.myklebust@hammerspace.com
>> 
>> --
>> Chuck Lever
>> 
>> 
>> 
> -- 
> Trond Myklebust
> CTO, Hammerspace Inc
> 4300 El Camino Real, Suite 105
> Los Altos, CA 94022
> www.hammer.space

--
Chuck Lever



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Trond Myklebust June 29, 2018, 8:58 p.m. UTC | #8
T24gRnJpLCAyMDE4LTA2LTI5IGF0IDE2OjQwIC0wNDAwLCBDaHVjayBMZXZlciB3cm90ZToNCj4g
PiBPbiBKdW4gMjksIDIwMTgsIGF0IDQ6MTUgUE0sIFRyb25kIE15a2xlYnVzdCA8dHJvbmRteUBo
YW1tZXJzcGFjZS5jDQo+ID4gb20+IHdyb3RlOg0KPiA+IA0KPiA+IE9uIEZyaSwgMjAxOC0wNi0y
OSBhdCAxNjowMiAtMDQwMCwgQ2h1Y2sgTGV2ZXIgd3JvdGU6DQo+ID4gPiA+IE9uIEp1biAyOSwg
MjAxOCwgYXQgMzo0OCBQTSwgVHJvbmQgTXlrbGVidXN0IDx0cm9uZG15QGhhbW1lcnNwYQ0KPiA+
ID4gPiBjZS5jDQo+ID4gPiA+IG9tPiB3cm90ZToNCj4gPiA+ID4gDQo+ID4gPiA+IE9uIEZyaSwg
MjAxOC0wNi0yOSBhdCAxNTozMyAtMDQwMCwgQ2h1Y2sgTGV2ZXIgd3JvdGU6DQo+ID4gPiA+ID4g
PiBPbiBKdW4gMjksIDIwMTgsIGF0IDM6MjkgUE0sIFRyb25kIE15a2xlYnVzdCA8dHJvbmRteUBo
YW1tZQ0KPiA+ID4gPiA+ID4gcnNwYQ0KPiA+ID4gPiA+ID4gY2UuYw0KPiA+ID4gPiA+ID4gb20+
IHdyb3RlOg0KPiA+ID4gPiA+ID4gDQo+ID4gPiA+ID4gPiBPbiBGcmksIDIwMTgtMDYtMjkgYXQg
MTQ6NDIgLTA0MDAsIFN0ZXZlIERpY2tzb24gd3JvdGU6DQo+ID4gPiA+ID4gPiA+IEZyb206IERh
bmllbCBTYW5kcy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FoMSBw75mxKLEksK3aMWhy4bCp37Lhm0NCj4gPiA+ID4gPiANCj4gPiA+ID4g
PiAtLQ0KPiA+ID4gPiA+IENodWNrIExldmVyDQo+ID4gPiA+ID4gDQo+ID4gPiA+ID4gDQo+ID4g
PiA+ID4gDQo+ID4gPiA+IA0KPiA+ID4gPiAtLSANCj4gPiA+ID4gVHJvbmQgTXlrbGVidXN0DQo+
ID4gPiA+IExpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lciwgSGFtbWVyc3BhY2UNCj4gPiA+ID4g
dHJvbmQubXlrbGVidXN0QGhhbW1lcnNwYWNlLmNvbQ0KPiA+ID4gDQo+ID4gPiAtLQ0KPiA+ID4g
Q2h1Y2sgTGV2ZXINCj4gPiA+IA0KPiA+ID4gDQo+ID4gPiANCj4gPiANCj4gPiAtLSANCj4gPiBU
cm9uZCBNeWtsZWJ1c3QNCj4gPiBDVE8sIEhhbW1lcnNwYWNlIEluYw0KPiA+IDQzMDAgRWwgQ2Ft
aW5vIFJlYWwsIFN1aXRlIDEwNQ0KPiA+IExvcyBBbHRvcywgQ0EgOTQwMjINCj4gPiB3d3cuaGFt
bWVyLnNwYWNlDQo+IA0KPiAtLQ0KPiBDaHVjayBMZXZlcg0KPiANCj4gDQo+IA0KLS0gDQpUcm9u
ZCBNeWtsZWJ1c3QNCkNUTywgSGFtbWVyc3BhY2UgSW5jDQo0MzAwIEVsIENhbWlubyBSZWFsLCBT
dWl0ZSAxMDUNCkxvcyBBbHRvcywgQ0EgOTQwMjINCnd3dy5oYW1tZXIuc3BhY2UNCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/xdr_stdio.c b/src/xdr_stdio.c
index 4410262..b902acd 100644
--- a/src/xdr_stdio.c
+++ b/src/xdr_stdio.c
@@ -103,10 +103,12 @@  xdrstdio_getlong(xdrs, lp)
 	XDR *xdrs;
 	long *lp;
 {
+	int32_t mycopy;
 
-	if (fread(lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
+	if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
 		return (FALSE);
-	*lp = (long)ntohl((u_int32_t)*lp);
+
+	*lp = (long)ntohl(mycopy);
 	return (TRUE);
 }
 
@@ -115,8 +117,14 @@  xdrstdio_putlong(xdrs, lp)
 	XDR *xdrs;
 	const long *lp;
 {
-	long mycopy = (long)htonl((u_int32_t)*lp);
+	int32_t mycopy;
+
+#if defined(_LP64)
+	if ((*lp > INT32_MAX) || (*lp < INT32_MIN))
+		return (FALSE);
+#endif
 
+	mycopy = (int32_t)htonl((int32_t)*lp);
 	if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
 		return (FALSE);
 	return (TRUE);