Commit Graph

229 Commits

Author SHA1 Message Date
Michael Kerrisk 552b1e5504 2.03 release 2005-06-02 13:11:04 +00:00
Michael Kerrisk 2ed34e110b 2.03 release 2005-06-02 13:10:44 +00:00
Michael Kerrisk de7639e575 Updated copyright date 2005-06-02 12:52:15 +00:00
Michael Kerrisk f7110f6014 Noted that any thread in a thread group can wait for a child
that one of them creates using fork().
2005-06-02 10:22:34 +00:00
Michael Kerrisk 9cbf71d215 Fix typo 2005-05-31 16:08:45 +00:00
Michael Kerrisk 6aacaf94e5 Hi Andries,
> The question came up whether execve of a suid binary while being ptraced
> would fail or ignore the suid part. The answer today seems to be the
> latter:
> 
> E.g. (in 2.6.11) security/dummy.c:
> 
> static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int 
> unsafe)
> {
>         if (bprm->e_uid != current->uid || bprm->e_gid != current->gid) {
>                 if ((unsafe & ~LSM_UNSAFE_PTRACE_CAP) &&
> !capable(CAP_SETUID)) {
>                         bprm->e_uid = current->uid;
>                         bprm->e_gid = current->gid;
>                 }
>         }
> }
> 
> and fs/exec.c:
> 
> void compute_creds(struct linux_binprm *bprm) {
>         int unsafe;
> 
>         unsafe = unsafe_exec(current);
>         security_bprm_apply_creds(bprm, unsafe);
> }
> 
> static inline int unsafe_exec(struct task_struct *p) {
>         int unsafe = 0;
>         if (p->ptrace & PT_PTRACED) {
>                 if (p->ptrace & PT_PTRACE_CAP)
>                         unsafe |= LSM_UNSAFE_PTRACE_CAP;
>                 else
>                         unsafe |= LSM_UNSAFE_PTRACE;
>         }
>         return unsafe;
> }
> 
> That is: if the process that calls execve() is being traced,
> the LSM_UNSAFE_PTRACE bit is et in unsafe and security_bprm_apply_creds()
> will make sure the suid/sgid bits are ignored.
> 
> ---
> 
> In my man page I do not read anything like that. It says
> 
>  EPERM  The process is being traced, the user is not the  superuser and
>         the file has an SUID or SGID bit set.
> and
> 
>  If  the current program is being ptraced, a SIGTRAP is sent to it after
>  a successful execve().
> 
>  If the set-uid bit is set on the program file pointed  to  by filename
>  the  effective user ID of the calling process is changed to that of the
>  owner of the program file.
> 
> So, maybe this sentence should be amended to read
> 
>  If the set-uid bit is set on the program file pointed  to  by filename
>  and the current process is not being ptraced, the  effective user ID
>  of the calling process is changed to ...

I changed your "current" to "calling" (to be consistent with the 
rest of the page), but otherwise applied as you suggest.

The revision will appear in man-pages-2.03, which I can release
any time now.  Are you avialable to do an upload tomorrow?
2005-05-31 16:07:24 +00:00
Michael Kerrisk 5e4e13a313 SEE ALSO s/threads/pthreads 2005-05-30 16:47:35 +00:00
Michael Kerrisk fb829c7406 nswap - not maintained. 2005-05-30 16:44:20 +00:00
Michael Kerrisk 3418ef2fdc FIXME: CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE are not yet documented 2005-05-30 16:43:37 +00:00
Michael Kerrisk 2202881e83 Noted changes in permissions required for SHM_LOCK/SHM_UNLOCK. 2005-05-30 11:58:06 +00:00
Michael Kerrisk 5bdccabd8e 1,$s/inherited/inheritable/g 2005-05-30 09:56:32 +00:00
Michael Kerrisk 9d2a7b1f62 Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier.
Added text on permissions required to send signal to owner.

====

Hello Johannes,

> Betreff: Inaccuracy of fcntl man page
> Datum: Mon, 2 May 2005 20:07:12 +0200

Thanks for yor note.

Sorry for the delay in getting back to you.  I needed to find time 
to set aside to look at the details.  Now I've finally got there.

> I have attached a simple program 

Thanks -- a little program is always helpful.

> that uses the fcntl system call in order
> to kill an arbitrary process of the same user.
> According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if 
> it has success.

Yes.

> If you strace the program while killing for exampe man running in another 
> terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid)
> will return EPERM, 

I confirm that I see this problem in 2.4, with both Unix domain 
and Internet domain sockets.

> where you can only find a very confusing explanation 
> in the fcntl man page.

I'm not sure what explanation you mean here.  As far as I can 
tell, the manual page just doesn't cover this point.

> I have looked into the kernel source of 2.4.30 and found out, that 
> net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix 
> sockets.

Yes, looks that way to me, as well,  And the 2.2 code looks 
similar.

> If pid is not your own pid or not your own process group, 
> the system call will return EPERM but will also set the pid 
> as you wanted to.

Yes.

> In the 2.6 kernel line, fcntl will react according the specification in
> the manual page.

Yes.

> If you also think, that one should clarify the return specification of 
> fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will 
> provide you with a patch for the manual page.

In fact I've written some new text under BUGS, which describes
the problem:

  In Linux 2.4 and earlier, there is bug that can occur  when  an
  unprivileged  process  uses  F_SETOWN to specify the owner of a
  socket file descriptor as a  process  (group)  other  than  the
  caller.   In this case, fcntl() can return -1 with errno set to
  EPERM, even when the owner process  (group)  is  one  that  the
  caller  has  permission to send signals to.  Despite this error
  return, the file descriptor owner is set, and signals  will  be
  sent to the owner.

Does that seem okay to you?

> Furthermore, it would be interseting to write there, what permissions 
> one need in order to send signals to processes via fcntl 

Good idea.  I added the following new text:

  Sending a signal to  the  owner  process  (group)  specified  by
  F_SETOWN  is  subject  to  the  same  permissions  checks as are
  described for kill(2), where the sending process is the one that
  employs F_SETOWN (but see BUGS below).

====


#define _GNU_SOURCE		/* needed to get the defines */
#include <fcntl.h>		/* in glibc 2.2 this has the needed
				   values defined */
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>


/**
 * Funnykill kills a program with fcntl
**/
int
main (int argc, char **argv)
{
  if (argc != 2)
    {
      fprintf (stderr, "Usage: funnykill <pid>\n");
      return 1;
    }

  int sockets[2];
  socketpair (AF_UNIX, SOCK_STREAM, 0, sockets);
  if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) 
      errMsg("fcntl-F_SETFL");
  if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) 
      errMsg("fcntl-F_SETOWN");
//  fcntl (sockets[0], F_SETOWN, getpid());
  if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) 
      errMsg("fcntl-_FSETSIG");
  write (sockets[1], "good bye", 9);
}
2005-05-20 12:11:25 +00:00
Michael Kerrisk 80ca8aba1d Added EAGAIN error description for umount2(). 2005-05-18 14:42:07 +00:00
Michael Kerrisk 8df37e4d66 Added MNT_EXPIRE, plus a few other tidy-ups. 2005-05-18 14:34:43 +00:00
Michael Kerrisk 6e5a730913 Added comment:
.\" For Unix domain sockets and regular files, EPERM is only returned in
.\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
.\" use mknod() to make these files.
2005-05-18 09:39:52 +00:00
Michael Kerrisk 99408a60ee Minor fixes to CLONE_THREAD material. 2005-05-18 08:29:38 +00:00
Michael Kerrisk e2fbf61d5a Added text on CLONE_THREAD and signals. 2005-05-17 16:21:20 +00:00
Michael Kerrisk fd8a5be48e Substantially enhanced discussion of CLONE_THREAD. 2005-05-17 15:06:30 +00:00
Michael Kerrisk c3c6c1f61f Update date in header 2005-05-12 09:08:33 +00:00
Michael Kerrisk 568105c673 Added 'rt_priority' and 'policy' to /proc/PID/stat. 2005-05-12 09:01:58 +00:00
Michael Kerrisk 0c6085e0c0 Minor changes to discussion of 'stat' signal fields. 2005-05-12 08:42:35 +00:00
Michael Kerrisk bf6c69c999 Vincent Fourmond / Joey (Martin) Schulze
Removed discussion of `[[:<:]]' and `[[:>:]]' since they do
not seem to be in the glibc implementation.
As per
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=295666


>   The regex.7.gz mentions that [[:>:]] and [[:<:]] are available to designate word boundaries.
> However, neither grep nor sed, which are build on the standard libc regcomp do recognise this syntax.
> Moreover, the small program here
>
> #include <regex.h>
> #include <sys/types.h>
> #include <iostream>
>
> using namespace std;
>
> int main()
> {
>   regex_t RE;
>   int err_code = regcomp(&RE, "[[:<:]]",
>              REG_EXTENDED);
>   char Buffer[100];
>   if(err_code) {
>     regerror(err_code, &RE, Buffer, 100);
>     cerr << "Error : " << Buffer << endl;
>   }
> }
>
>
> produces the following error message:
>
> Error : Invalid character class name
2005-05-11 16:06:19 +00:00
Michael Kerrisk 80ee1d97e1 as per http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=304242 2005-05-11 15:14:54 +00:00
Michael Kerrisk f82a9fac78 Pavel Heimlich <tropikhajma@seznam.cz>
>   I've noticed that man pages 
> console_ioctl.4
> console.4
> mouse.4
> tty.4
> vcs.4 
> refer to ttys (4), which should in fact be ttyS (4).

Hello Pavel,

The man command on Linux is actually case insensitive with respect
to page names, so "man ttys" works!  Nevertheless, I agree with 
you, and I've changed the pages as you suggest.
2005-05-11 14:18:48 +00:00
Michael Kerrisk 948fb4ed37 __W* flags can't be used with waitid() 2005-05-10 17:16:28 +00:00
Michael Kerrisk a69b6bda71 Added CLONE_SYSVSEM, CLONE_UNTRACED, CLONE_STOPPED. 2005-05-10 16:48:27 +00:00
Michael Kerrisk 6a916f1c28 Noted that lock conversions are not atomic. 2005-05-10 06:43:47 +00:00
Michael Kerrisk 5984622e7b Added_CS_GNU_LIBC_VERSION and_CS_GNU_LIBPTHREAD_VERSION. 2005-05-09 10:53:56 +00:00
Michael Kerrisk 0359df8c95 Added FIXME 2005-05-09 10:37:48 +00:00
Michael Kerrisk 2d93f55ce7 Added FIXME (capabilities are per-thread) 2005-05-03 14:27:04 +00:00
Michael Kerrisk d2b761645c Added a NOTE to point out that the affinity mask is actually a
per-thread attribute that can be adjusted independently
for each thread in a thread group.
2005-05-03 14:24:08 +00:00
Michael Kerrisk 8ea6b1affa Added FIXME for UDP_CORK 2005-05-03 12:26:25 +00:00
Michael Kerrisk 6fbc0235a6 Add text to note that sched_setaffinity() will migrate the
affected process to one of the specified CPUs if necessary.
2005-05-03 11:24:33 +00:00
Michael Kerrisk 75ced2e8a3 Noted aberrant Linux behaviour w.r.t. new
attaches to a segment that has already been marked for deletion.
2005-04-25 08:36:43 +00:00
Michael Kerrisk dde7d1a947 Typos/grammar fixes. 2005-04-25 07:08:00 +00:00
Michael Kerrisk 0ab63df41c Formatting fixes 2005-04-25 05:16:35 +00:00
Michael Kerrisk 5f33625167 Added some pages to SEE ALSO 2005-04-21 09:11:01 +00:00
Michael Kerrisk cbc84c6e74 Fix typo 2005-04-19 10:58:30 +00:00
Michael Kerrisk 30e6794a25 Clarified wording of the 'pid == -1' case. 2005-04-19 10:53:55 +00:00
Michael Kerrisk 79e860131f ru_nswap has never contained useful information.
Kernel 2.6.6 clarified that with a patch
("[PATCH] eliminate nswap and cnswap").  See also:
http://www.ussg.iu.edu/hypermail/linux/kernel/0404.1/0720.html
2005-04-19 09:02:05 +00:00
Michael Kerrisk 17490d2f8a Fix spelling mistake 2005-04-18 15:19:09 +00:00
Michael Kerrisk d301ee6c72 Fix typos and spelling mistakes 2005-04-18 14:25:45 +00:00
Michael Kerrisk 704a18f06d Fixed typos and spelling mistakes 2005-04-18 13:35:29 +00:00
Michael Kerrisk 4667b1b5fe 2.03 initial changes 2005-04-14 09:26:47 +00:00
Michael Kerrisk 5931962772 2.03 initial changes 2005-04-14 09:25:37 +00:00
Michael Kerrisk 7502db97e2 Fix typo in 2.02 release 2005-04-14 09:24:26 +00:00
Michael Kerrisk cb80891c88 The default zoneinfo directory is now (was: /usr/local/etc/zoneinfo)
As per http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=267471
2005-04-14 08:49:43 +00:00
Michael Kerrisk faa64f705b Setup for 2.02 release. 2005-04-05 06:55:35 +00:00
Michael Kerrisk e8a095046c Updates for 2.02 release. 2005-04-05 06:44:35 +00:00
Michael Kerrisk 7c088cb1d8 Date: Fri, 28 Jan 2005 11:00:59 +0000
From: Jamie Lokier <jamie@shareable.org>
To: mtk-manpages@gmx.net
Subject: Update to fcntl(2) man page

Hi Michael,

I have a correction to the fcntl(2) man page.

Under the section for F_SETOWN, which describes how to set the
recipient process or group for SIGIO signals, see this paragraph:

	The process or process  group  to  receive  the  signal  can  be
	selected  by  using  the F_SETOWN command to the fcntl function.
	If the file descriptor is a socket, this also selects the recip-
	ient  of SIGURG signals that are delivered when out-of-band data
	arrives on that socket.  (SIGURG is sent in any situation  where
	select(2) would report the socket as having an "exceptional con-
	dition".)  If the file  descriptor  corresponds  to  a  terminal
	device,  then  SIGIO  signals are sent to the foreground process
	group of the terminal.

I would like to add an additional paragraph:

	The value given to F_SETOWN has a slightly different meaning
	when F_SETSIG is used in a multi-threaded process.

	If a non-zero value is given to F_SETSIG, then a positive
	value given to F_SETOWN identifies a specific thread within a
	process, instead of a whole process.  The value is a thread id
	not a process id, so you may need to pass the result of
	gettid() instead of getpid() to get sensible results when
	F_SETSIG is used.  (Thread ids are different from process ids,
	although they have the same value for some threads depending
	on details of the threading library used).

Also, this is the first paragraph of the F_SETSIG section:

	Sets the signal sent when input or output becomes  possible.   A
	value of zero means to send the default SIGIO signal.  Any other
	value (including SIGIO) is the signal to send  instead,  and  in
	this  case additional info is available to the signal handler if
	installed with SA_SIGINFO.

I'd like to append another paragraph right after that one:

	Additionally, passing a non-zero value to F_SETSIG changes the
	signal recipient from a whole process to a specific thread
	within a process.  The section on F_SETOWN gives more details.


Date: Thu, 7 Apr 2005 17:58:59 +0100
From: Jamie Lokier <jamie@shareable.org>
To: Michael Kerrisk <mtk-manpages@gmx.net>
Subject: Re: Update to fcntl(2) man page

[[...]]

> I've been trying to follow the kernel source code to verify
> the details you describe above.  The relevant place is the 
> 'switch' in fs/fcntl.c::send_sigio_to_task() right?

Yes.

> Also, for NPTL, perhaps one needs to mention that for the main
> thread, gettid() == getpid(), which allows the traditional
> use of F_SETSIG / F_SETOWN in programs consisting of a single
> thread -- right?

Yes, that makes sense.  It's also fine for the "main thread" with
NPTL, so programs which spawn threads can still use F_SETOWN/F_SETSIG
in the main thread using getpid().


Date: Tue, 12 Apr 2005 15:25:49 +0100
From: Jamie Lokier <jamie@shareable.org>
To: Michael Kerrisk <mtk-manpages@gmx.net>
Subject: Re: Update to fcntl(2) man page

Michael Kerrisk wrote:
>   F_SETOWN
>          Set  the  process ID or process group ID that will
>          receive SIGIO and SIGURG  signals  for  events  on
>          file  descriptor fd.  A process ID is specified as
>          a positive value; a process group ID is  specified
>          as a negative value.
> 
>          If  you  set  the  O_ASYNC  status  flag on a file
>          descriptor (either by providing this flag with the
>          open(2)  call,  or by using the F_SETFL command of
>          fcntl), a SIGIO signal is sent whenever  input  or
>          output  becomes  possible on that file descriptor.
>          F_SETSIG can be used to obtain delivery of a  sig&#8208;
>          nal other than SIGIO.
> 
>          If  the  file  descriptor  fd  refers to a socket,
>          F_SETOWN also selects the recipient of SIGURG sig&#8208;
>          nals  that  are  delivered  when  out-of-band data
>          arrives on that socket.  (SIGURG is  sent  in  any
>          situation  where select(2) would report the socket
>          as having an "exceptional condition".)
> 
>          If a non-zero value is  given  to  F_SETSIG  in  a
>          multi-threaded  process,  then  a  positive  value
>          value given to F_SETOWN has a  different  meaning:
>          instead  of being a process ID identifying a whole
>          process, it is a thread ID identifying a  specific
>          thread  within a process.  Consequently, it may be
>          necessary to pass F_SETOWN the result of  gettid()
>          instead  of  getpid() to get sensible results when
>          F_SETSIG is used.   (In  current  Linux  threading
>          implementations,  a main thread's thread ID is the
>          same as its process ID.  This means that a single-
>          threaded  program can equally use gettid() or get&#8208;
>          pid() in this scenario.)  Note, however, that  the
>          statements  in  this paragraph do not apply to the
>          SIGURG signal generated for out-of-band data on  a
>          socket:  this  signal  is  always sent to either a
>          process or a process group, depending on the value
>          given to F_SETOWN.
> 
> And the first part of the description of F_SETSIG now reads:
> 
>   F_SETSIG
>          Sets the signal sent when input or output  becomes
>          possible.   A  value  of  zero  means  to send the
>          default SIGIO signal.  Any other value  (including
>          SIGIO)  is the signal to send instead, and in this
>          case additional info is available  to  the  signal
>          handler if installed with SA_SIGINFO.
> 
>          Additionally, passing a non-zero value to F_SETSIG
>          changes the signal recipient from a whole  process
>          to  a  specific  thread within a process.  See the
>          desciption of F_SETOWN for more details.
> 
> Does the above seem okay to you?

It looks good, but: 

  1. An omission: It mentions that SIGURG is always sent to the whole
     process.  SIGIO is also sent to the whole process, instead of
     queueing a thread-specific signal, when the signal queue is full.
     Programs that mustn't miss readiness events need to handle it.

  2. The description could be confusing to LinuxThreads users, because
     all the signals are thread-specific in LinuxThreads.


Date: Tue, 12 Apr 2005 16:53:19 +0100
From: Jamie Lokier <jamie@shareable.org>
To: Michael Kerrisk <mtk-manpages@gmx.net>
Subject: Re: Update to fcntl(2) man page

Michael Kerrisk wrote:
> >   1. An omission: It mentions that SIGURG is always sent to the whole
> >      process.  SIGIO is also sent to the whole process, instead of
> >      queueing a thread-specific signal, when the signal queue is full.
> >      Programs that mustn't miss readiness events need to handle it.
> 
> Sorry -- can you point me to the relevant code for the 
> above point please.

In 2.6:

	switch (fown->signum) {
		siginfo_t si;
		default:
			/* Queue a rt signal with the appropriate fd as its
			   value.  We use SI_SIGIO as the source, not 
			   SI_KERNEL, since kernel signals always get 
			   delivered even if we can't queue.  Failure to
			   queue in this case _should_ be reported; we fall
			   back to SIGIO in that case. --sct */
			si.si_signo = fown->signum;
			si.si_errno = 0;
		        si.si_code  = reason;
			/* Make sure we are called with one of the POLL_*
			   reasons, otherwise we could leak kernel stack into
			   userspace.  */
			if ((reason & __SI_MASK) != __SI_POLL)
				BUG();
			if (reason - POLL_IN >= NSIGPOLL)
				si.si_band  = ~0L;
			else
				si.si_band = band_table[reason - POLL_IN];
			si.si_fd    = fd;
			if (!send_sig_info(fown->signum, &si, p))
				break;
		/* fall-through: fall back on the old plain SIGIO signal */
		case 0:
			send_group_sig_info(SIGIO, SEND_SIG_PRIV, p);

2.4 is exactly the same, except:

		/* fall-through: fall back on the old plain SIGIO signal */
		case 0:
			send_sig(SIGIO, p, 1);

The fall-through happens when send_sig_info() fails, which happens
when the real-time signal queue is full.

Programs using a queued signal to track file readiness efficiently (as
an alternative to select/poll), must listen for SIGIO in addition to
the real-time signal, as otherwise they will miss notifications when
the queue is full (which happens often on a busy server).

Multi-threaded programs using NPTL must be aware this SIGIO is
process-wide - so receiving it on one thread must cause all threads to
assume a queued signal may be lost.  Programs using LinuxThreads do
not have to assume this (but it's safe if they do).


Date: Wed, 13 Apr 2005 17:25:44 +0100
From: Jamie Lokier <jamie@shareable.org>
To: Michael Kerrisk <mtk-manpages@gmx.net>
Subject: Re: Update to fcntl(2) man page

Michael Kerrisk wrote:
> I added a few more sentences to the end of that paragraph
> on F_SETOWN:
> 
>     If a non-zero value is given  to  F_SETSIG  in  a multi-threaded
>     process  running with  a threading  library that supports thread
>     groups (e.g., NPTL),  then  a  positive  value  value  given to
>     F_SETOWN has a different meaning: instead  of being a process ID
>     identifying a whole  process, it is a  thread  ID identifying  a
>     specific thread  within a process.  Consequently, it may be nec-
>     essary to pass  F_SETOWN the result of gettid() instead  of  get
>     pid() to  get sensible results  when F_SETSIG is used.  (In cur-
>     rent Linux threading implementations, a main thread's thread  ID
>     is  the  same  as  its  process  ID.   This means that a single-
>     threaded program can equally use gettid() or  getpid()  in  this
>     scenario.)  Note, however, that the statements in this paragraph
>     do not apply to the SIGURG signal generated for out-of-band data
>     on a socket: this signal is always sent to either a process or a
>     process group, depending on the value given to  F_SETOWN.   Note
>     also  that Linux imposes a limit on the number of real-time sig-
>     nals that may be queued to a process (see getrlimit(2) and  sig-
>     nal(7)) and if this limit is reached, then the kernel reverts to
>     delivering SIGIO, and  this  signal is  delivered to the  entire 
>     process rather than to a specifc thread.
> 
> Look oay now?

Looks ood.

It will take a minor genius to translate that to working
multi-threaded RT-SIGIO code without a tutorial -- and in fact I
haven't heard of any program or library which does it (though I'm
trying to write one) -- but technically it seems to include everything.
2005-04-05 05:54:09 +00:00