DAC permissions not correctly enforced

Bug #190329 reported by Andrew Oakley
282
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Fix Released
High
Kees Cook
Hardy
Fix Released
High
Kees Cook
Intrepid
Fix Released
High
Kees Cook
ntfs-3g (Ubuntu)
Invalid
Undecided
Unassigned
Hardy
Invalid
Undecided
Unassigned
Intrepid
Invalid
Undecided
Unassigned

Bug Description

I seem to be able to get a privilege elevation when mounting an ntfs device in fstab. This is on Hardy Alpha with all updates installed to date (2008-02-08).

Take for example the /etc/fstab line:

UUID=3E7EA4A67EA45903 /mnt/sda3 ntfs noexec,umask=337,uid=aoakley,gid=aoakley 0 1

If I mount this with mount /mnt/sda3 all looks fine. Doing ls -l /mnt shows as expected:

dr--r----- 1 aoakley aoakley 12288 2008-02-08 22:51 sda3

However there seem to be two security issues. Firstly if I log on as "aoakley", I am able to WRITE to this mount, even though the permissions are read-only. For example, when logged on as aoakley, echo "hello world" >/mnt/sda3/x.txt works!

Secondly, even when I log on as an entirely unrelated user who is NOT a member of the "aoakley" group, I can STILL write to this mount! For example, when logged on as guest (who is not a member of aoakley), echo "hello from guest" >/mnt/sda3/x.txt still works fine!

Am I significantly misunderstanding user/group permissions on mounted devices, or is this a bug?

Revision history for this message
Martin Erik Werner (arand) wrote :

I'm guessing this is the same problem as described in bug #198403 (now marked as duplicate of this).

In that case I can confirm this for Hardy Beta, fully updated as of postdate.

(See my bug report for some extra info and a screenshot of the process.)

Revision history for this message
Martin Erik Werner (arand) wrote :

Ok, I was able to get the desired result (write-protection) by adding the option "ro" in fstab, like so:

ro,defaults,umask=027,gid=46 0 1

strange that this should work and not other things...

especially since they did work before.

Kees Cook (kees)
description: updated
Revision history for this message
Martin Erik Werner (arand) wrote :

Correction: Above fix is does not have desired effect completely:

It disables write access for both group and root, and I'd like to keep root-write...

Revision history for this message
Martin Erik Werner (arand) wrote :

I have now tried:

In fstab:
switching "ntfs">"ntfs-3g"
adding nouser option
changing gid=46 to gid=0
adding setuid=0 and setgid=0 options.
removing all options except "defaults"

... and everything ends with me still being able to write to the ntfs partition without being root.

Revision history for this message
Martin Erik Werner (arand) wrote :

This persists on Hardy Final...

Revision history for this message
Szabolcs Szakacsits (szaka) wrote :

Fixed in kernel 2.4.25.

Revision history for this message
Szabolcs Szakacsits (szaka) wrote :

Fixed in kernel 2.6.25.

Revision history for this message
Martin Erik Werner (arand) wrote :

This meaning that this will be fixed in 8.04.1 probably?

Revision history for this message
Leann Ogasawara (leannogasawara) wrote :

Szabolcs Szakacsits, you mention this is fixed upstream in 2.6.25. Do you have a patch you could point us to or did you just test the upstream 2.6.25 kernel to verify this is no longer an issue. We'd likely want to get this into 8.04.1 but will need to narrow down the fix to apply. I'll do some searching/testing for the exact patch but if you know it off hand that would be great. Thanks.

Revision history for this message
Szabolcs Szakacsits (szaka) wrote :

Search for the FUSE kernel module default_permission fix.

Revision history for this message
Szabolcs Szakacsits (szaka) wrote :

Sorry, the option is default_permissions ('s' in the end).

Revision history for this message
Leann Ogasawara (leannogasawara) wrote :

Thanks for the info. I'm including the upstream git commit id and patch below just for reference. I was able to reproduce the original bug reported here against the 2.6.24-16.30 kernel shipped in Hardy final. I downloaded the 2.6.24-16.30 hardy kernel source and applied the upstream patch. Although the patch does indeed prevent writes when read only permissions are specified, further testing shows it will prohibit reads as well for the user even though read permissions are granted. Also, with the patch applied, writes were never allowed even when write permissions are granted. I've attached the output of a small debug session to show the results. I also tested the upstream 2.6.25 vanilla kernel to see if there were possibly other patches that would fully resolve the issue but I found the same results with the upstream vanilla 2.6.25 kernel as with the Ubuntu 2.6.24 kernel + upstream patch.

Szabolcs, just curious if you have done any further testing with the upstream patch/kernel and if you experience the same results? Thanks.

commit 1a823ac9ff09cbdf39201df37b7ede1f9395de83
Author: Miklos Szeredi <email address hidden>
Date: Sat Feb 23 15:23:27 2008 -0800

    fuse: fix permission checking

    I added a nasty local variable shadowing bug to fuse in 2.6.24, with the
    result, that the 'default_permissions' mount option is basically ignored.

    How did this happen?

     - old err declaration in inner scope
     - new err getting declared in outer scope
     - 'return err' from inner scope getting removed
     - old declaration not being noticed

    -Wshadow would have saved us, but it doesn't seem practical for
    the kernel :(

    More testing would have also saved us :((

    Signed-off-by: Miklos Szeredi <email address hidden>
    Cc: <email address hidden>
    Signed-off-by: Andrew Morton <email address hidden>
    Signed-off-by: Linus Torvalds <email address hidden>

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 7fb514b..c4807b3 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -906,7 +906,7 @@ static int fuse_permission(struct inode *inode, int mask, struct nam
        }

        if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
- int err = generic_permission(inode, mask, NULL);
+ err = generic_permission(inode, mask, NULL);

                /* If permission is denied, try to refresh file
                   attributes. This is also needed, because the root

Revision history for this message
Szabolcs Szakacsits (szaka) wrote :

I can't see problems in your debug session. Your umask setting causes the permission denied errors, no 'x' on the directories. Try e.g. fmask=337,dmask=227 with the 'ro' mount and it will work fine. Similar logic for 'rw' mounts.

Revision history for this message
Leann Ogasawara (leannogasawara) wrote :

Thanks Szabolcs :) Confirming that using the fmask and dmask parameters as recommended resolve previous issues on patched kernel.

I believe the ubuntu security team is merging patches this week so this should most likely be available in 8.04.1 . Thanks.

Changed in linux:
assignee: nobody → keescook
importance: Undecided → High
milestone: none → ubuntu-8.04.1
status: New → Triaged
Steve Langasek (vorlon)
Changed in linux:
importance: Undecided → High
milestone: none → ubuntu-8.04.1
status: New → Triaged
Changed in ntfs-3g:
status: New → Confirmed
Changed in linux:
assignee: nobody → keescook
Steve Langasek (vorlon)
Changed in linux:
milestone: ubuntu-8.04.1 → none
Revision history for this message
Steve Langasek (vorlon) wrote :

dropping the milestone, since this will be handled via security channels.

Changed in linux:
milestone: ubuntu-8.04.1 → none
Kees Cook (kees)
Changed in linux:
status: Triaged → Fix Committed
status: Triaged → Fix Released
Revision history for this message
Neil Wilson (neil-aldur) wrote :

The current version of the hardy kernel (2.6.24-19.34) still does not enforce the 'default permissions' mount option for fuse mounted filesystems.

I'm using glusterfs which relies upon the 'default permissions' option to do file mode checking, and at the moment any user can write in any directory, remove and overwrite files owned by root and generally wreak havoc.

All that is needed to fix the bug is to remove the word 'int' from fs/fuse/dir.c around line 906 in the kernel, as described in the patch above

Any chance of getting that patch merged into the hardy kernel?

Changed in linux:
status: Fix Committed → In Progress
Revision history for this message
Kees Cook (kees) wrote :

Hi! Yes, that's what the previous "Fix Committed" bug status means. :) A Hardy security update is pending and will be published soon that includes this fix.

Changed in linux:
status: In Progress → Fix Committed
Revision history for this message
Kees Cook (kees) wrote :
Changed in linux:
status: Fix Committed → Fix Released
Revision history for this message
Steve Langasek (vorlon) wrote :

TTBOMK, this bug is resolved with the kernel fix and requires no update to ntfs-3g.

Changed in ntfs-3g:
status: Confirmed → Invalid
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.