Mike O'Connor of SGI reported this flaw where a normal user who has access to write to a NFS mounted fs can panic an NFS client and therefore cause a local DoS using O_DIRECT. Quote: Any O_DIRECT write to an NFS file where the user buffer starts with a valid mapped page and contains an unmapped page, will crash in this way. I haven't followed the code, but O_DIRECT reads with similar user buffers will probably also crash albeit in different ways. Details: when nfs_get_user_pages() calls get_user_pages(), it detects and correctly handles get_user_pages() returning an error, which happens if the first page covered by the user buffer's address range is unmapped. However, if the first page is mapped but some subsequent page isn't, get_user_pages() will return a positive number which is less than the number of pages requested (this behaviour is sort of analagous to a short write() call and appears to be intentional). nfs_get_user_pages() doesn't detect this and hands off the array of pages (whose last few elements are random rubbish from the newly allocated array memory) to it's caller, whence they go to nfs_direct_write_seg(), which then totally ignores the nr_pages it's given, and calculates its own idea of how many pages are in the array from the user buffer length. Needless to say, when it comes to transmit those uninitialised page* pointers, we see a crash in the network stack.
Proposed fix from Mike: @@ -88,6 +88,15 @@ nfs_get_user_pages(int rw, unsigned long *pages, NULL); up_read(¤t->mm->mmap_sem); } + + BUG_ON(result > page_count); + /* + * If we got fewer pages than expected from get_user_pages(), + * the user buffer runs off the end of a mapping; return EFAULT. + */ + if (result > 0 && result < page_count) + result = -EFAULT; + return result; } Trond followed up with: Since get_user_pages() hasn't returned an error here, I think you'll find you also need to ensure that the pages it returned get released correctly. Also, a result of zero pages could, AFAICS, create the same panic. Perhaps something like the following instead? if (result >= 0 && result < page_count) { nfs_free_user_pages(*pages, result, 0); *pages = NULL; result = -EFAULT; }
embargo set at 20060227:1600
Created attachment 128145 [details] purposed patch
committed in stream U4 build 34.24. A test kernel with this patch is available from http://people.redhat.com/~jbaron/rhel4/
An advisory has been issued which should help the problem described in this bug report. This report is therefore being closed with a resolution of ERRATA. For more information on the solution and/or where to find the updated files, please follow the link below. You may reopen this bug report if the solution does not work for you. http://rhn.redhat.com/errata/RHSA-2006-0493.html