public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* link() security
@ 2002-04-11 23:21 xystrus
  2002-04-12  1:15 ` Chris Wright
  2002-04-15 14:44 ` Patrick J. LoPresti
  0 siblings, 2 replies; 19+ messages in thread
From: xystrus @ 2002-04-11 23:21 UTC (permalink / raw)
  To: linux-kernel

Hi all,

If this subject has been beaten to death in the past, a link to the
discussion is really all I need...

Is there a good reason why a user can successfully link() a file to
which they do not have any access?

Here's a scenario:

Many linux systems, like Slackware and SuSE, favor the permissions
1777 for the mail spool directory.  This is a good policy from a
security perspective, as it prevents mail utilities from requiring
SUID/SGID root or mail privileges to create a user's spool and/or lock
files.

Now, people often point to several problems with this scheme.  Such
as the following:

 * users can create an unlimited number of files in this directory,
   potentially using up all availabile inodes

 * users can use the spool as scratch space, and potentially fill up
   the spool filesystem

 * users can create links to other users' spool files.

The first two really are very minor problems in comparison to a
potential security breach (priviledge elevation), and can be solved
with quota and/or site policy.  Troublesome users who ignore policy
can be dealt with appropriately.

The last one is a bit sticky though.  As a regular user, I can create
a hard link to someone's spool file, and call it whatever I want.
This isn't a major problem, because the resulting link retains the
permissions and ownership of the original file; therefore a user who
does this can't gain access to anything they didn't already have
access to...  However, it certainly can constitute an abuse of
resources and/or site policy.

There are cases where this can be a security problem though; and
what's more, there's no apparent way to identify who created the link,
since the link retains ownership of the original file.  If, for
example, a malicious user noticed that a particular new user's spool
file had not been created, he could link(mymailbox, newusermailbox).
And now (ignoring locking issues in the spool area), one of two things
will happen:

 a) if the mail delivery programs run with privileges (despite not
    needing to with 1777 permissions on the spool), the new user's
    mail will be delivered to the malicious user's spool.

 b) if they don't run with privileges, a mail delivery error should
    result, alerting the system administrators to the problem.

Either way, this isn't really a great situation.  But here's the worst
part:  a malicious user can frame someone, say another user they hold
a grudge against, as having done this.  Since the link() call succeeds
regardless of permissions on the file, the malicious user can also
call link(framedusermailbox, newusermailbox)!  The system
administration team has no way to identify who created the file.  They
can't even look and see who was on at time of creation, because the
creation time is the same as that of the original file.  Worse still,
system administrators who are not aware of this behavior of link() may
mistakenly believe that the file was created by the framed user, and
recommend expulsion or termination of their employment/access/whatever
on that basis.

I've tested that this works on Red Hat 7.1 with pristine 2.4.17
sources and using the ln command.  I have not actually written a
program that calls link() in this manner.  However the ln command is
not SUID, so I can imagine no other way this would work...

In my opinion, the solution to this problem is to check that the file
being linked is owned by the UID of the calling process, or that the
UID is root (or that the process has the appropriate capabilities -- a
facility that I'm not overly familiar with).  If not, the call to
link() should fail with EACCES or EPERM.


Thanks,
Xy


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: link() security
@ 2002-04-13 17:48 Hank Leininger
  0 siblings, 0 replies; 19+ messages in thread
From: Hank Leininger @ 2002-04-13 17:48 UTC (permalink / raw)
  To: linux-kernel

On 2002-04-13, xystrus <xystrus@haxm.com> wrote:

> On Sat, Apr 13, 2002 at 05:59:54PM +0100, Alan Cox wrote:
> > > http://openwall.com.  Work based on Solar Designer's Openwall patch
> > > has been brought forward to more recent 2.4 and 2.5 kernels.  Both
> > > the following projects implement the Openwall secure link feature:
> > > 
> > > http://grsecurity.net
> > > http://lsm.immunix.org
> > > 
> > > This can break some applications that make assumptions wrt. link(2)
> > > (Courier MTA for example).
> > 
> > How practical is it to make this a mount option and to do so cleanly ?

...I like the mount option idea, will explore for my next patch... ;)

> Perhaps two options: one to allow creation of the link only when the
> UIDs match; and the other to allow the link when GIDs match, to keep
> Courier happy?

Well, if UIDs match there's no problem.  From Openwall (2.2.20 fs/namei.c
at/near line 1312):
        if (current->fsuid != inode->i_uid &&
		...other tests

I've been using a modification[1] of the Openwall patch to allow the GID
case just as you describe, for some in-house secure drop-directory where
multiple daemons share a GID to play in their queue directory.  I've never
used courier but it sounds like that may work w/this change as well.  From
2.2.20-hap-5 fs/namei.c line 1318:
#ifdef CONFIG_SECURE_NOTSOMUCH
	/*
	 * Let users hard link to files in their group.
	 */
	    current->fsgid != inode->i_gid &&
#endif

This works well, but the CONFIG_ option name is chosen for a reason; this
has some side effects which may not be desirable.  Allowing GID matches
will often result in users being able to hard link to each others files, on
systems where users are all in group 'users' by default (and users have
files in non-0700 directories).

I know the grsecurity guys have ported most of both Openwall and HAP to
2.4, not positive if they carried over the NOTSOMUCH option but it'd be
simple to add.  Keep in mind all this violates POSIX standards so isn't
likely to ever be in-kernel, but the patches should be maintained for some
reasonably large value of $forever.

[1] http://www.theaimsgroup.com/~hlein/hap-linux/, the patch has many
    other things, just search for CONFIG_SECURE_NOTSOMUCH.

--
Hank Leininger <hlein@progressive-comp.com> 
  

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: link() security
@ 2002-04-15 19:36 Chris Adams
  2002-04-15 19:55 ` H. Peter Anvin
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Adams @ 2002-04-15 19:36 UTC (permalink / raw)
  To: linux-kernel

Once upon a time, H. Peter Anvin <hpa@zytor.com> said:
>Not to mention the fact that the single file mailbox design is itself
>flawed.  Mailboxes are fundamentally directories, which news server
>authors quickly realized.

Funny that news server authors realized that storing messages in files
by themselves is a bad idea, while at the same time mail server authors
realized that storing messages together in a single file is a bad idea.
Which one is right?  Both?  Neither?
-- 
Chris Adams <cmadams@hiwaay.net>
Systems and Network Administrator - HiWAAY Internet Services
I don't speak for anybody but myself - that's enough trouble.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2002-05-06  5:00 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-11 23:21 link() security xystrus
2002-04-12  1:15 ` Chris Wright
2002-04-13 16:59   ` Alan Cox
2002-04-13 17:02     ` xystrus
2002-04-14  1:49     ` Chris Wright
2002-04-15 14:44 ` Patrick J. LoPresti
2002-04-15 19:25   ` H. Peter Anvin
2002-04-15 22:48     ` Alan Cox
2002-04-15 23:05       ` H. Peter Anvin
2002-04-15 23:28         ` Alan Cox
2002-04-15 23:14           ` H. Peter Anvin
2002-04-16  0:01             ` Kurt Wall
2002-04-15 21:41   ` xystrus
2002-05-06  5:00     ` Albert D. Cahalan
  -- strict thread matches above, loose matches on Subject: below --
2002-04-13 17:48 Hank Leininger
2002-04-15 19:36 Chris Adams
2002-04-15 19:55 ` H. Peter Anvin
2002-04-15 20:36   ` Patrick J. LoPresti
2002-04-16  1:37     ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox