* question about potential integer truncation in cifs_set_file_size
@ 2015-09-26 14:31 PaX Team
[not found] ` <5606AC37.16935.51F2ED39-tVCe0bXVy/VhMnff8nq0I0CAg8bcNmFB@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: PaX Team @ 2015-09-26 14:31 UTC (permalink / raw)
To: linux-cifs-u79uwXL29TY76Z2rM5mHXA
Cc: Steve French, re.emese-Re5JQEeQqe8AvxtiuMwx3w,
spender-JNS0hek0TMl4qEwOxq4T+Q
hi all,
fs/cifs/inode.c:cifs_set_file_size can truncate iattr.ia_size from loff_t
(long long) to unsigned int here:
io_parms.length = attrs->ia_size;
and i'm wondering if this is intentional. based on a quick read of the code,
it seems that ia_size can at this point have a value over 4G (e.g., via a
call to truncate) and the ->set_file_size callback will transmit the full
64 bit value however in case of specific failures a (fallback?) call to
CIFSSMBWrite would be made with the truncated size.
FTR, this issue was detected with the upcoming version of the size overflow
plugin we have in PaX/grsecurity and there're a handful of similar cases in
the tree where potentially unwanted or unnecessary integer truncations occur,
this being one of these. any opinion/help is welcome!
cheers,
PaX Team
^ permalink raw reply [flat|nested] 3+ messages in thread[parent not found: <5606AC37.16935.51F2ED39-tVCe0bXVy/VhMnff8nq0I0CAg8bcNmFB@public.gmane.org>]
* Re: question about potential integer truncation in cifs_set_file_size [not found] ` <5606AC37.16935.51F2ED39-tVCe0bXVy/VhMnff8nq0I0CAg8bcNmFB@public.gmane.org> @ 2015-09-28 20:57 ` Steve French [not found] ` <CAH2r5mvWtbsru8HAphsGhukP-YHNSF+99D9v1BbBbNMeiaeCAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Steve French @ 2015-09-28 20:57 UTC (permalink / raw) To: pageexec-Y8qEzhMunLyT9ig0jae3mg Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Steve French, re.emese-Re5JQEeQqe8AvxtiuMwx3w, spender-JNS0hek0TMl4qEwOxq4T+Q On Sat, Sep 26, 2015 at 9:31 AM, PaX Team <pageexec-Y8qEzhMunLyT9ig0jae3mg@public.gmane.org> wrote: > hi all, > > fs/cifs/inode.c:cifs_set_file_size can truncate iattr.ia_size from loff_t > (long long) to unsigned int here: > > io_parms.length = attrs->ia_size; > > and i'm wondering if this is intentional. based on a quick read of the code, > it seems that ia_size can at this point have a value over 4G (e.g., via a > call to truncate) and the ->set_file_size callback will transmit the full > 64 bit value however in case of specific failures a (fallback?) call to > CIFSSMBWrite would be made with the truncated size. Good catch. The bug here is in an error path that you probably wouldn't notice except to very very old Windows (or DOS!) systems (ie even before Window 2000) or perhaps when mounted to buggy CIFS servers which don't support the normal SetFileInfo levels. The actual bug is that the length and offsets fields are backwards. Fortunately, this code path returns immediately from write (since the length is non-zero with a buffer pointer of zero) without doing damage, and you wouldn't even notice the bug since most every CIFS server supports the normal way of setting the file size (via SetFileInfo) and doesn't require falling back to the DOS (!) way of setting file size by writing zero bytes at an offset. > FTR, this issue was detected with the upcoming version of the size overflow > plugin we have in PaX/grsecurity and there're a handful of similar cases in > the tree where potentially unwanted or unnecessary integer truncations occur, > this being one of these. any opinion/help is welcome! If you find others let me know (other than the identical bug in the error path immediately below the one you just pointed out). -- Thanks, Steve ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <CAH2r5mvWtbsru8HAphsGhukP-YHNSF+99D9v1BbBbNMeiaeCAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: question about potential integer truncation in cifs_set_file_size [not found] ` <CAH2r5mvWtbsru8HAphsGhukP-YHNSF+99D9v1BbBbNMeiaeCAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2015-09-29 11:02 ` PaX Team 0 siblings, 0 replies; 3+ messages in thread From: PaX Team @ 2015-09-29 11:02 UTC (permalink / raw) To: Steve French Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Steve French, re.emese-Re5JQEeQqe8AvxtiuMwx3w, spender-JNS0hek0TMl4qEwOxq4T+Q On 28 Sep 2015 at 15:57, Steve French wrote: > > FTR, this issue was detected with the upcoming version of the size overflow > > plugin we have in PaX/grsecurity and there're a handful of similar cases in > > the tree where potentially unwanted or unnecessary integer truncations occur, > > this being one of these. any opinion/help is welcome! > > If you find others let me know (other than the identical bug in the > error path immediately below the one you just pointed out). sure, i will, though the current (very specific) analysis found only those questionable cases that i reported (here and some other lists). if you (or anyone else) have ideas for more specific analysis (checking invariants, API use, etc), we can take a look though gcc plugins have very limited view on the source code, so only those properties can be checked that are still visible in the middle end (we found the above case exactly because the underlying code looks the same whether the integer truncation is intentional or not, so we had to exclude them as false positives in our instrumentation but still wanted to manually verify them). PS: it seems that you didn't CC me on the actual patch ;) ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-29 11:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-26 14:31 question about potential integer truncation in cifs_set_file_size PaX Team
[not found] ` <5606AC37.16935.51F2ED39-tVCe0bXVy/VhMnff8nq0I0CAg8bcNmFB@public.gmane.org>
2015-09-28 20:57 ` Steve French
[not found] ` <CAH2r5mvWtbsru8HAphsGhukP-YHNSF+99D9v1BbBbNMeiaeCAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-29 11:02 ` PaX Team
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox