From owner-freebsd-bugs@FreeBSD.ORG Sun Oct 1 17:20:29 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B1E4116A415 for ; Sun, 1 Oct 2006 17:20:29 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9821E43D55 for ; Sun, 1 Oct 2006 17:20:28 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k91HKSKk001837 for ; Sun, 1 Oct 2006 17:20:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k91HKS9S001836; Sun, 1 Oct 2006 17:20:28 GMT (envelope-from gnats) Resent-Date: Sun, 1 Oct 2006 17:20:28 GMT Resent-Message-Id: <200610011720.k91HKS9S001836@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, douglas steinwand Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 616B416A70D for ; Sun, 1 Oct 2006 17:18:02 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1342D43D46 for ; Sun, 1 Oct 2006 17:18:02 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k91HI1tm070629 for ; Sun, 1 Oct 2006 17:18:01 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k91HI115070628; Sun, 1 Oct 2006 17:18:01 GMT (envelope-from nobody) Message-Id: <200610011718.k91HI115070628@www.freebsd.org> Date: Sun, 1 Oct 2006 17:18:01 GMT From: douglas steinwand To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: bin/103873: login(1) SEGFAULT on unsuccessful login X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Oct 2006 17:20:29 -0000 >Number: 103873 >Category: bin >Synopsis: login(1) SEGFAULT on unsuccessful login >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Oct 01 17:20:27 GMT 2006 >Closed-Date: >Last-Modified: >Originator: douglas steinwand >Release: 6.2-PRERELEASE >Organization: >Environment: FreeBSD thinkpad.fx.org 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #4: Sat Sep 30 20:42:55 PDT 2006 root@thinkpad.fx.org:/usr/obj/usr/src/sys/HAWK6 i386 >Description: It seems that the login_audit.c doesn't check that pwd is non-NULL before dereferencing it. Below is a patch with a possible solution. >How-To-Repeat: At the console, press Enter a few times, or run login(1) from a shell. If you do not successfuly login, the application exits and syslog notes something like: Oct 1 10:08:51 thinkpad kernel: pid 62854 (login), uid 0: exited on signal 11 >Fix: --- usr.bin/login/login_audit.c.orig Tue Sep 5 16:53:21 2006 +++ usr.bin/login/login_audit.c Sun Oct 1 09:46:41 2006 @@ -51,6 +51,17 @@ */ static au_tid_t tid; +/* returns -1 on failure, 0 on success */ +static int +get_pwd(uid_t *uid, gid_t *gid) +{ + if (pwd == NULL) + return(-1); + *uid = pwd->pw_uid; + *gid = pwd->pw_gid; + return(0); +} + /* * The following tokens are included in the audit record for a successful * login: header, subject, return. @@ -62,11 +73,14 @@ int aufd; au_mask_t aumask; auditinfo_t auinfo; - uid_t uid = pwd->pw_uid; - gid_t gid = pwd->pw_gid; + uid_t uid; + gid_t gid; pid_t pid = getpid(); long au_cond; + if (get_pwd(&uid, &gid) == -1) + return; + /* If we are not auditing, don't cut an audit record; just return. */ if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) { if (errno == ENOSYS) @@ -140,8 +154,8 @@ errx(1, "login: Audit Error: au_to_subject32() failed"); } else { /* We know the subject -- so use its value instead. */ - uid = pwd->pw_uid; - gid = pwd->pw_gid; + if (get_pwd(&uid, &gid) == -1) + errx(1, "login: Audit Error: au_to_subject32() failed"); if ((tok = au_to_subject32(uid, geteuid(), getegid(), uid, gid, pid, pid, &tid)) == NULL) errx(1, "login: Audit Error: au_to_subject32() failed"); @@ -172,10 +186,13 @@ int aufd; au_mask_t aumask; auditinfo_t auinfo; - uid_t uid = pwd->pw_uid; - gid_t gid = pwd->pw_gid; + uid_t uid; + gid_t gid; pid_t pid = getpid(); long au_cond; + + if (get_pwd(&uid, &gid) == -1) + return; /* If we are not auditing, don't cut an audit record; just return. */ if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) { >Release-Note: >Audit-Trail: >Unformatted: