[tex-k] Kpathsea and SUID/SGID programs

Jan Vida xvida at informatics.muni.cz
Thu May 13 10:57:56 CEST 2004


Hello
While working for my school project I've found that kpathsea doesn't
handle well SUID and SGID programs. The problem lies in the function
kpse_readable_file() in file readable.c, which checks permissions for
found files. It relies on the system function access() (via macro
READABLE). Unfortunately, this call doesn't take into account rights
gained by the SUID/SGID mechanism and so might fail, even when the calling
program does in fact have the right to read the found file.
The following patch corrents the problem. When READABLE fails and errno is
EACCES, it checks if the calling program is SUID/SGID and if so, it simply
tries to open the file and if it succeedes, sets return value to name.
Otherwise it just prints the error message (unles hushed) and returns NULL.


*** readable.c	Tue Jan 26 21:19:33 1999
--- readable.new.c	Wed May 12 15:43:44 2004
***************
*** 16,21 ****
--- 16,23 ----
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

+ #include <fcntl.h>
+
  #include <kpathsea/config.h>
  #include <kpathsea/c-stat.h>
  #include <kpathsea/readable.h>
***************
*** 89,94 ****
--- 91,97 ----
    }
  #else /* ! WIN32 */
    struct stat st;
+   int fd;

    if (READABLE (name, st)) {
      ret = (string) name;
***************
*** 107,118 ****
  #endif /* ENAMETOOLONG */

    } else { /* Some other error.  */
      if (errno == EACCES) { /* Maybe warn them if permissions are bad.  */
!       if (!kpse_tex_hush ("readable")) {
          perror (name);
        }
      }
-     ret = NULL;
    }
  #endif
    return ret;
--- 110,126 ----
  #endif /* ENAMETOOLONG */

    } else { /* Some other error.  */
+     ret = NULL;
      if (errno == EACCES) { /* Maybe warn them if permissions are bad.  */
!
! /* if we are SUID or SGID, we'll just try to open the file */
!       if (((getuid() != geteuid()) || (getgid() != getegid())) &&
!         ((fd = open(name, O_RDONLY)) > 0) && (close(fd) == 0))
!         ret = (string) name;
!       else if (!kpse_tex_hush ("readable")) {
          perror (name);
        }
      }
    }
  #endif
    return ret;

Jan Vida
xvida at fi.muni.cz

"Devil finds work for idle hands."



More information about the tex-k mailing list