Bug 67464 - kdecore problem with chown
Summary: kdecore problem with chown
Status: RESOLVED WORKSFORME
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Oswald Buddenhagen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-07 02:09 UTC by Philippe Rigault
Modified: 2004-01-21 07:58 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Rigault 2003-11-07 02:09:41 UTC
Version:            (using KDE KDE 3.1.93)
Installed from:    Compiled From Sources
Compiler:          GCC 3.3.2 
OS:          Linux

This is new to the 3.2 branch (tested on 3.1.93), it does not happen on 3.1.3.

I am getting error messages like this upon launching a konsole:
    kdecore (KProcess): WARNING: Cannot chown /dev/pts/7
    kdecore (KProcess): Reason Operation not permitted
    kgrantpty: determined a strange device name `/dev/ptmx'.
    kdecore (KProcess): WARNING: chownpty failed for device ::/dev/pts/7
    This means the communication can be eavesdropped.
 
Looking at the code, I found that this happens within KPty::open() , which is defined in kdelibs-3.1.93/kdecore/kpty.cpp.

The relevant part is:

------------------------BEGIN_EXCERPT_FROM_kpty.cpp-------------------------------
#define TTY_GROUP "tty"
...
#if defined(HAVE_OPENPTY)
    if (openpty(&d->masterFd, &d->slaveFd, NULL, NULL, NULL) == 0)
    {
      d->ttyName = ttyname(d->slaveFd);

      d->needGrantPty = false;

      /* Get the group ID of the special `tty' group.  */
      struct group* p = getgrnam(TTY_GROUP);    /* posix */
      gid_t gid = p ? p->gr_gid : getgid ();    /* posix */

      if (fchown(d->slaveFd, (uid_t) -1, gid) < 0)
      {
         int e = errno;
         d->needGrantPty = true;
         kdWarning(175) << "Cannot chown " << d->ttyName << endl
                        << "Reason " << strerror(e) << endl;
      }
      else if (fchmod(d->slaveFd, S_IRUSR|S_IWUSR|S_IWGRP) < 0)
      {
         int e = errno;
         d->needGrantPty = true;
         kdWarning(175) << "Cannot chmod " << d->ttyName << endl
                        << "Reason " << strerror(e) << endl;
      }
      goto gotpty;
    }
#endif
...
 gotpty:
  if (!chownpty(true))
  {
    kdWarning(175)
      << "chownpty failed for device " << ptyName << "::" << d->ttyName
      << "\nThis means the communication can be eavesdropped." << endl;
  }
------------------------END_EXCERPT_FROM_kpty.cpp-------------------------------

The problem comes from the call to fchown(): 

According to fchown(3) manual page:
       The owner  of  a  file  may
       change the group of the file to any group of which that owner is a mem-
       ber.  The super-user may change the group arbitrarily.

Users are not a member of the 'tty' group. Therefore, the call to fchown (from user space, this part is not setuid root) will always fail because its third argument is a group that the user is not part of.

Regarding this line:
      kgrantpty: determined a strange device name `/dev/ptmx'.
It seems kgrantpty fails early because it uses a wrong pty name:
 
------------------------BEGIN_EXCERPT_FROM_kgrantpty.c-------------------------------
  /* matches /dev/pty?? */
  if (strlen(pty) < 8 || strncmp(pty,"/dev/pty",8))
  {
    fprintf(stderr,"%s: determined a strange device name `%s'.\n",argv[0],pty);
    return 1; /* FAIL */
  }
------------------------END_EXCERPT_FROM_kgrantpty.c-------------------------------

Hope this helps
Comment 1 Philippe Rigault 2003-11-07 06:37:04 UTC
I just confirmed that those error messages disappear when the user is a member of the 'tty' group.
Comment 2 Oswald Buddenhagen 2003-11-07 13:09:35 UTC
this is a hairy one. the pty stuff is an incredible mess, the manual pages of the various OSes don't document openpty properly. i have the impression that the branch that fails for you is not needed at all ... dunno. what does
   ls -l `tty`
say in a konsole? what in an xterm?
Comment 3 Philippe Rigault 2003-11-07 15:30:13 UTC
In a konsole:
crw-------    1 prigault prigault 136,   3 Nov  7 06:26 /dev/pts/3

In an xterm:
crw--w----    1 prigault prigault 136,   7 Nov  7 06:26 /dev/pts/7

In a console (outside X):
crw--w----    1 prigault tty        4,   2 Nov  7 06:25 /dev/tty2
Comment 4 Oswald Buddenhagen 2004-01-10 19:40:16 UTC
i just committed a patch that could/should cure the problem. please verify.
Comment 5 Philippe Rigault 2004-01-21 07:58:25 UTC
Affirmative! Problem gone in 3.1.95.
Thanks much.

Looks like you knocked that branch altogether in kpty.cpp.