Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 50315 - pam_console_apply segfaults with minimal /etc/group
Summary: pam_console_apply segfaults with minimal /etc/group
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: PAM Gentoo Team (OBSOLETE)
URL:
Whiteboard:
Keywords:
: 43315 68794 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-05-06 21:45 UTC by Owen Gunden
Modified: 2005-02-03 07:42 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch disabling pam_console_apply in bootmisc for udev systems (bootmisc.patch,528 bytes, patch)
2004-05-06 21:47 UTC, Owen Gunden
Details | Diff
patch disabling pam_console_apply in halt.sh for udev systems (halt.sh.patch,483 bytes, patch)
2004-05-06 21:47 UTC, Owen Gunden
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Owen Gunden 2004-05-06 21:45:10 UTC
On a pure udev system, running pam_console_apply on bootup segfaults after
erroring with "getgrnam failed for usb".

It's not currently run for devfs systems.  I can tell this because in /etc/bootmisc there is the following:
        [ -x /sbin/pam_console_apply -a ! -c /dev/.devfsd ] && \
            /sbin/pam_console_apply -r
and in /etc/halt.sh there is similar.  Changing this to
        [ -x /sbin/pam_console_apply -a ! -c /dev/.devfsd -a ! -f /dev/.udev ] \
            && /sbin/pam_console_apply -r
makes it not apply to udev systems either.

I'll attach patches for bootmisc and halt.sh, but it's just that tiny change.

I've been patching baselayout for several versions now manually--it would be nice if this would get incorporated.

Reproducible: Always
Steps to Reproduce:
1. on a udev system, run pam_console_apply -r
Actual Results:  
getgrnam failed for usb
segmentation fault  pam_console_apply -r

Expected Results:  
pam_console_apply should not be run (at least, i think this is a safe solution,
since it's not run for devfs which is practically all gentoo machines)

Portage 2.0.50-r6 (default-x86-1.4, gcc-3.3.3, glibc-2.3.3_pre20040420-r0,
2.6.5-gentoo)
=================================================================
System uname: 2.6.5-gentoo i686 AMD Athlon(tm) XP 1800+
Gentoo Base System version 1.4.10
distcc 2.13 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [disabled]
Autoconf: sys-devel/autoconf-2.59-r3
Automake: sys-devel/automake-1.8.3
ACCEPT_KEYWORDS="x86 ~x86"
AUTOCLEAN="yes"
CFLAGS="-march=athlon-xp -O2 -pipe"
CHOST="i686-pc-linux-gnu"
COMPILER="gcc3"
CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config
/usr/kde/3/share/config /usr/lib/mozilla/defaults/pref /usr/share/config
/usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/
/usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/
/usr/share/texmf/xdvi/ /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=athlon-xp -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs ccache sandbox"
GENTOO_MIRRORS="http://mirror.datapipe.net/gentoo
ftp://ftp.ussg.iu.edu/pub/linux/gentoo
ftp://csociety-ftp.ecn.purdue.edu/pub/gentoo/ http://gentoo.mirrors.pair.com/
http://adelie.polymtl.ca/"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="3dnow X aalib alsa apache2 avi berkdb bonobo cdr crypt cups dga directfb
dvd dvdr encode esd fbcon foomaticdb gdbm gif glut gnome gtk gtk2 gtkhtml guile
imap imlib java jpeg libg++ libwww mad maildir mikmod mmx motif mozcalendar
mozilla moznocompose moznoirc mozsvg mozxmlterm mpeg ncurses nptl offensive
oggvorbis opengl pam pdflib perl plotutils png ppds python quicktime readline
ruby samba scanner slang spell ssl svga tcltk tcpd tetex tiff truetype usb
video_cards_nvidia x86 xml2 xmms xv zlib"
Comment 1 Owen Gunden 2004-05-06 21:47:18 UTC
Created attachment 30898 [details, diff]
patch disabling pam_console_apply in bootmisc for udev systems
Comment 2 Owen Gunden 2004-05-06 21:47:50 UTC
Created attachment 30899 [details, diff]
patch disabling pam_console_apply in halt.sh for udev systems
Comment 3 Patrizio Bassi 2004-08-03 01:22:15 UTC
i got the same error, but for cdwriter and not usb.


for bootmisc and hast.sh scripts

please fix in next releases.
thanx
Comment 4 Gregorio Guidi (RETIRED) gentoo-dev 2004-08-03 01:54:26 UTC
segfault after "getgrnam failed... "? well, I just found this in the pam tarball:
pam-0.77-patches/gentoo-patches/pam-0.77-console-reset.patch

Probaly one of the most stupid patches ever.

--- Linux-PAM-0.77/modules/pam_console/config.y.console-reset   2003-07-10 22:50:26.000000000 +0200
+++ Linux-PAM-0.77/modules/pam_console/config.y 2003-07-10 22:54:22.000000000 +0200
@@ -415,13 +415,13 @@
            if (pwd == NULL) {
                _pam_log(LOG_ERR, FALSE, "getpwnam failed for %s",
                         c->revert_owner ? c->revert_owner : "root");
-               return -1;
+               pwd->pw_uid = 0;
            }
            grp = _pammodutil_getgrnam(pamh, c->revert_group ? c->revert_group : "root");
            if (grp == NULL) {
                 _pam_log(LOG_ERR, FALSE, "getgrnam failed for %s",
                          c->revert_group ? c->revert_group : "root");
-                return -1;
+               grp->gr_gid = 0;
             }
            if (c->device_class->list)
                chmod_files(c->revert_mode ? c->revert_mode : "0600",
Comment 5 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-08-13 01:51:50 UTC
azarah/agriffis: could the bootmisc change make it into the baselayout, and what's your opinion on removing the PAM console-reset patch?
Comment 6 Owen Gunden 2004-08-24 19:45:02 UTC
Call me crazy, but I think this bug has something in common with bug #42139; at least for the halt.sh issue.
Comment 7 SpanKY gentoo-dev 2004-10-16 10:37:21 UTC
added additional checks for udev to cvs, thanks
Comment 8 SpanKY gentoo-dev 2004-10-25 16:10:06 UTC
*** Bug 43315 has been marked as a duplicate of this bug. ***
Comment 9 SpanKY gentoo-dev 2004-10-25 16:10:42 UTC
*** Bug 68794 has been marked as a duplicate of this bug. ***
Comment 10 Martin Schlemmer (RETIRED) gentoo-dev 2004-10-26 13:34:52 UTC
This is wrong.  If you get that, it means pam_console_apply could not get
the group info from /etc/group for the 'usb' group.  It works flawlessly
here (and I would like to keep it doing so on my few systems):

-----
nosferatu linux-2.6-bk # ls -l /dev/.udev
-rw-r--r--  1 root root 0 Oct 24 05:12 /dev/.udev
nosferatu linux-2.6-bk # ls -l /dev/usb/
total 0
crw-r--r--  1 root root 180,  0 Oct 26 22:26 lp0
crw-r--r--  1 root root 180,  1 Oct 26 22:26 lp1
crw-------  1 root root 180, 64 Oct 26 22:30 rio500
nosferatu linux-2.6-bk # /sbin/pam_console_apply
nosferatu linux-2.6-bk # ls -l /dev/usb/
total 0
crw-r--r--  1 root   root 180,  0 Oct 26 22:26 lp0
crw-r--r--  1 root   root 180,  1 Oct 26 22:26 lp1
crw-------  1 azarah root 180, 64 Oct 26 22:30 rio500
nosferatu linux-2.6-bk # /sbin/pam_console_apply -r
nosferatu linux-2.6-bk # ls -l /dev/usb/
total 0
crw-r--r--  1 root root 180,  0 Oct 26 22:26 lp0
crw-r--r--  1 root root 180,  1 Oct 26 22:26 lp1
crw-------  1 root root 180, 64 Oct 26 22:30 rio500
nosferatu linux-2.6-bk #
-----

So basically we have two options:
1) Find out what (im guessing missing usb entry in /etc/group) is broken
on affected systems, or
2) Fix pam_console_apply to not segfault if getgrnam fails.

Would anybody that are affected by this issue be willing to try and track
it down ?
Comment 11 Owen Gunden 2004-10-26 15:35:48 UTC
> This is wrong.  If you get that, it means pam_console_apply could not get
> the group info from /etc/group for the 'usb' group.

Yes, I think you're right--I'm the original reporter and I now believe that
pam_console_apply should be called even with udev (I've experienced situations
where I don't own audio devices correctly after logging out and in again).

On my system there's no usb group.  Believe it or not, this could be because
I'm an idiot and removed it manually a while back.  I should try to add it.

[tinker tinker tinker..]

Fixed; pam_console_apply -r no longer segfaults.

Wow, what an idiot I am..
Comment 12 Martin Schlemmer (RETIRED) gentoo-dev 2004-10-27 10:55:43 UTC
No problem.  I will have a look into why pam_console_apply segfaults, and we
can revert the changes to bootmisc and halt.sh again.
Comment 13 Gregorio Guidi (RETIRED) gentoo-dev 2004-10-27 12:09:22 UTC
Well... it's because the abovementioned patch does "grp->gr_gid = 0;"
when grp is NULL.

Sorry if I wasn't clear in my previous post.
Comment 14 Martin Schlemmer (RETIRED) gentoo-dev 2004-10-28 12:28:52 UTC
Ah, right.  My mistake though, I did not read all of the bug :P
Comment 15 Redeeman 2004-10-31 05:36:06 UTC
hmm, the thing vapier gave me didnt work, however, when i then removed it again, it worked, i dont know what did it
Comment 16 Martin Schlemmer (RETIRED) gentoo-dev 2004-10-31 08:09:53 UTC
This should be a better patch (fixed for pam-0.77 and pam-0.77-r2):

-----
--- Linux-PAM-0.77/modules/pam_console/pam_console_apply.c.console-reset        2003-07-08 05:16:28.000000000 +0200
+++ Linux-PAM-0.77/modules/pam_console/pam_console_apply.c      2003-07-10 22:50:26.000000000 +0200
@@ -41,8 +41,9 @@
        va_list args;
        if (debug_p && !debug) return;
         va_start(args, format);
-       fprintf(stderr, format, args);
+       vfprintf(stderr, format, args);
        va_end(args);
+       fprintf(stderr, "\n");
 }

 int
--- Linux-PAM-0.77/modules/pam_console/config.y.az      2004-10-31 14:39:41.519539120 +0200
+++ Linux-PAM-0.77/modules/pam_console/config.y 2004-10-31 14:42:44.110781032 +0200
@@ -425,6 +425,8 @@
 reset_permissions(pam_handle_t *pamh, const char *consolename, int nonroot_ok) {
     struct passwd *pwd;
     struct group *grp;
+    uid_t pw_uid;
+    gid_t gr_gid;
     config *c;
     GSList *cl;

@@ -439,20 +441,24 @@
            if (pwd == NULL) {
                _pam_log(LOG_ERR, FALSE, "getpwnam failed for %s",
                         c->revert_owner ? c->revert_owner : "root");
-               return -1;
+               pw_uid = 0;
+           } else {
+               pw_uid = pwd->pw_uid;
            }
            grp = _pammodutil_getgrnam(pamh, c->revert_group ? c->revert_group : "root");
            if (grp == NULL) {
                 _pam_log(LOG_ERR, FALSE, "getgrnam failed for %s",
                          c->revert_group ? c->revert_group : "root");
-                return -1;
-            }
+               gr_gid = 0;
+            } else {
+               gr_gid = pwd->pw_uid;
+           }
            if (c->device_class->list)
                chmod_files(c->revert_mode ? c->revert_mode : "0600",
-                           pwd->pw_uid, grp->gr_gid, NULL, c->device_class->list);
+                           pw_uid, gr_gid, NULL, c->device_class->list);
            else
                chmod_files(c->revert_mode ? c->revert_mode : "0600",
-                           pwd->pw_uid, grp->gr_gid, c->device_class->name, NULL);
+                           pw_uid, gr_gid, c->device_class->name, NULL);
        }
     }
     return 0;