Bug 488192 - login: access("/nfs-home/.hushlogin", R_OK) = -1 EACCES (Permission denied)
Summary: login: access("/nfs-home/.hushlogin", R_OK) = -1 EACCES (Permission denied)
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: util-linux
Version: 5.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 5.5
Assignee: Karel Zak
QA Contact: Martin Cermak
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-03-03 04:58 UTC by Michael Kearey
Modified: 2018-11-14 18:01 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-01-13 23:44:37 UTC
Target Upstream Version:
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:0085 0 normal SHIPPED_LIVE util-linux bug fix update 2011-01-12 17:29:18 UTC

Description Michael Kearey 2009-03-03 04:58:17 UTC
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 05:01:48 UTC
Created attachment 333833 [details]
Patch to resolve motd problem

Comment 2 Karel Zak 2009-03-03 08:18:55 UTC
(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 09:17:03 UTC
Fixed in upstream code.

Comment 11 Martin Cermak 2010-11-29 14:24:08 UTC
Comment #9 => VERIFIED

Comment 13 errata-xmlrpc 2011-01-13 23:44:37 UTC
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.