Bug 488192 - login: access("/nfs-home/.hushlogin", R_OK) = -1 EACCES (Permission denied)
login: access("/nfs-home/.hushlogin", R_OK) = -1 EACCES (Permission denied)
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: util-linux (Show other bugs)
5.2
All Linux
medium Severity medium
: rc
: 5.5
Assigned To: Karel Zak
Martin Cermak
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-02 23:58 EST by Michael Kearey
Modified: 2011-01-13 18:44 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-01-13 18:44:37 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Patch to resolve motd problem (614 bytes, patch)
2009-03-03 00:01 EST, Michael Kearey
no flags Details | Diff

  None (edit)
Description Michael Kearey 2009-03-02 23:58:17 EST
Description of problem:

As an NFS client with home directories on mounted NFS share - If the NFS server exports the share with default root squashed, login cannot access the filesystem to check for the existence of .hushlogin file - login uses the file to determine if motd and last is shown/updated on login.

Version-Release number of selected component (if applicable):
Reported originally in util-linux-2.13-0.47.el5-x86_64 but problem exists in all versions of util-linux packages for RHEL5.

How reproducible:
100%

Steps to Reproduce:
1. Create a user on NFS server for example:
motdtest:x:3333:3333:None:/home/motdtest:/bin/bash

2. Export motdtest user's home directory:
/home/motdtest 10.0.0.1(rw)

3. service nfs start

4. Create a user on NFS client that uses mount poiny /nfs-home for home directory:
motdtest:x:3333:3333:None:/nfs-home:/bin/bash

5. Create entry in /etc/fstab on NFS client
10.0.0.2:/home/motdtest /nfs-home nfs nfsvers=3,hard,intr,tcp 0 0
mkdir /nfs-home

6. Mount the NFS export
mount /nfs-home

7. login at console on NFS client and create .hushlogin file :
touch .hushlogin

8. Logout and login again as motdtest user


Actual results:
The meesage of the day is displayed, and last is updated. 




Expected results:
The message of the day should be shown and last should not be updated.

Additional info:

strace attached to mingetty tty1 shows :

getuid()                                = 0
getegid()                               = 0
setregid(4294967295, 3333)              = 0
setreuid(0, 3333)                       = 0
access("/nfs-home/.hushlogin", R_OK)    = -1 EACCES (Permission denied)
setuid(0)                               = 0
setreuid(0, 0)                          = 0
setregid(4294967295, 0)      


These system calls line up with the code from login.c:


  {
      char tmpstr[MAXPATHLEN];
      uid_t ruid = getuid();
      gid_t egid = getegid();

      /* avoid snprintf - old systems do not have it, or worse,
         have a libc in which snprintf is the same as sprintf */
      if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN)
              quietlog = 0;
      else {
              sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
              setregid(-1, pwd->pw_gid);
              setreuid(0, pwd->pw_uid);
              quietlog = (access(tmpstr, R_OK) == 0);
              setuid(0); /* setreuid doesn't do it alone! */
              setreuid(ruid, 0);
              setregid(-1, egid);
      }


A small patch that uses setresuid and setresgid instead follows as attachement. It resolves the problem in my tests. I have not explored the consequences of using setresuid/setresgid fully, but I do think it is minimal.
Comment 1 Michael Kearey 2009-03-03 00:01:48 EST
Created attachment 333833 [details]
Patch to resolve motd problem
Comment 2 Karel Zak 2009-03-03 03:18:55 EST
(In reply to comment #0)
> Actual results:
> The meesage of the day is displayed, and last is updated. 
> 
> Expected results:
> The message of the day should be shown and last should not be updated.
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
The quietlog (quiet mode) does not control last log update. This mode 
enable/disable printing of the last login time and message of the day. 
That's all. The user cannot control last log _update_ at all.

> 
> Additional info:
> 
> strace attached to mingetty tty1 shows :
> 
> getuid()                                = 0
> getegid()                               = 0
> setregid(4294967295, 3333)              = 0
> setreuid(0, 3333)                       = 0
> access("/nfs-home/.hushlogin", R_OK)    = -1 EACCES (Permission denied)

Hmm.. you're right, the access(2) is exception, man page:

  The  check  is done using the calling process’s real UID and GID,
  rather than the effective IDs as is done when actually attempting an
  operation (e.g., open(2)) on  the  file. This allows set-user-ID
  programs to easily determine the invoking user’s authority.

Thanks, good catch!
Comment 3 Karel Zak 2009-04-10 05:17:03 EDT
Fixed in upstream code.
Comment 11 Martin Cermak 2010-11-29 09:24:08 EST
Comment #9 => VERIFIED
Comment 13 errata-xmlrpc 2011-01-13 18:44:37 EST
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0085.html

Note You need to log in before you can comment on or make changes to this bug.