lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGXu5jLnDa9g5z76OQaF5BGbHssQVSgc3KCSwOVT9__mLww9Yg@mail.gmail.com>
Date:	Wed, 22 Feb 2012 11:10:04 -0800
From:	Kees Cook <keescook@...omium.org>
To:	Ingo Molnar <mingo@...e.hu>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Marcin Slusarz <marcin.slusarz@...il.com>,
	linux-kernel@...r.kernel.org, Randy Dunlap <rdunlap@...otime.net>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	linux-doc@...r.kernel.org, linux-fsdevel@...r.kernel.org,
	kernel-hardening@...ts.openwall.com
Subject: Re: [PATCH] fs: hardlink creation restriction cleanup

On Wed, Feb 22, 2012 at 2:23 AM, Ingo Molnar <mingo@...e.hu> wrote:
>
> * Kees Cook <keescook@...omium.org> wrote:
>
>> Clean-up of hardlink restriction logic, as suggested by Andrew Morton.
>>
>> Signed-off-by: Kees Cook <keescook@...omium.org>
>> ---
>>  fs/namei.c |   59 +++++++++++++++++++++++++++++++++++++++++------------------
>>  1 files changed, 41 insertions(+), 18 deletions(-)
>>
>> diff --git a/fs/namei.c b/fs/namei.c
>> index 8ed4e00..a4a21a5 100644
>> --- a/fs/namei.c
>> +++ b/fs/namei.c
>> @@ -693,46 +693,69 @@ static inline int may_follow_link(struct path *link)
>>  }
>>
>>  /**
>> + * safe_hardlink_source - Check for safe hardlink conditions
>> + * @inode: the source inode to hardlink from
>> + *
>> + * Return false if at least one of the following conditions:
>> + *    - inode is not a regular file
>> + *    - inode is setuid
>> + *    - inode is setgid and group-exec
>> + *    - access failure for read and write
>> + *
>> + * Otherwise returns true.
>> + */
>> +static bool safe_hardlink_source(struct inode *inode)
>> +{
>> +     mode_t mode = inode->i_mode;
>> +
>> +     /* Special files should not get pinned to the filesystem. */
>> +     if (!S_ISREG(mode))
>> +             return false;
>> +     /* Setuid files should not get pinned to the filesystem. */
>> +     if (mode & S_ISUID)
>> +             return false;
>> +     /* Executable setgid files should not get pinned to the filesystem. */
>> +     if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
>> +             return false;
>> +     /* Hardlinking to unreadable or unwritable sources is dangerous. */
>> +     if (inode_permission(inode, MAY_READ | MAY_WRITE))
>> +             return false;
>> +
>> +     return true;
>
> A really minor nitpick, could we use this form please:
>
> static bool safe_hardlink_source(struct inode *inode)
> {
>        mode_t mode = inode->i_mode;
>
>        /* Special files should not get pinned to the filesystem. */
>        if (!S_ISREG(mode))
>                return false;
>
>        /* Setuid files should not get pinned to the filesystem. */
>        if (mode & S_ISUID)
>                return false;
>
>        /* Executable setgid files should not get pinned to the filesystem. */
>        if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
>                return false;
>
>        /* Hardlinking to unreadable or unwritable sources is dangerous. */
>        if (inode_permission(inode, MAY_READ | MAY_WRITE))
>                return false;
>
>        return true;
> }
>
> Those separate blocks of comments and conditions stand out much
> nicer this way, making it way easier on the eyes - to my eyes at
> least ;-)

Heh, sure. I've sent v2 now. :)

-Kees

-- 
Kees Cook
ChromeOS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ