]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
fs: nfsd: Fix signedness bug in compare_blob
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Fri, 5 Dec 2014 15:40:07 +0000 (16:40 +0100)
committerJiri Slaby <jslaby@suse.cz>
Mon, 26 Jan 2015 13:39:02 +0000 (14:39 +0100)
commitb2abe3c2f4217e3df748a348d2536bae103afc9e
tree650aae97435d28885214a88952d995b9b82466a2
parent5ea7d58ceb75a5902252eca83df628b63fb913f6
fs: nfsd: Fix signedness bug in compare_blob

commit ef17af2a817db97d42dd2ec0a425231748e23dbc upstream.

Bugs similar to the one in acbbe6fbb240 (kcmp: fix standard comparison
bug) are in rich supply.

In this variant, the problem is that struct xdr_netobj::len has type
unsigned int, so the expression o1->len - o2->len _also_ has type
unsigned int; it has completely well-defined semantics, and the result
is some non-negative integer, which is always representable in a long
long. But this means that if the conditional triggers, we are
guaranteed to return a positive value from compare_blob.

In this case it could be fixed by

-       res = o1->len - o2->len;
+       res = (long long)o1->len - (long long)o2->len;

but I'd rather eliminate the usually broken 'return a - b;' idiom.

Reviewed-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
fs/nfsd/nfs4state.c