From nobody@FreeBSD.org  Fri Aug  9 01:56:25 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 984D0216
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 01:56:25 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 85CD523F3
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 01:56:25 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r791uPMt059596
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 Aug 2013 01:56:25 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r791uPX5059585;
	Fri, 9 Aug 2013 01:56:25 GMT
	(envelope-from nobody)
Message-Id: <201308090156.r791uPX5059585@oldred.freebsd.org>
Date: Fri, 9 Aug 2013 01:56:25 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] *access*(2) does not handle invalid amodes properly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181155
>Category:       kern
>Synopsis:       [libc] [patch] *access*(2) does not handle invalid amodes properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 09 02:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Apr 18 17:30:00 UTC 2014
>Originator:     Garrett Cooper
>Release:        10-CURRENT
>Organization:
EMC Isilon
>Environment:
FreeBSD fuji-current.local 10.0-CURRENT FreeBSD 10.0-CURRENT #12 c3d9dc4-dirty: Thu Aug  8 18:48:47 PDT 2013     root@fuji-current.local:/usr/obj/usr/src/sys/FUJI-NOCOMPAT  i386
>Description:
Invalid access modes aren't properly handled in FreeBSD, so feeding in a valid like -1 won't result in a failed call.
>How-To-Repeat:
access("/", -1);
>Fix:


Patch attached with submission follows:

From ceea6405b65a81a336b7c804dbe6c2dd0d84b72c Mon Sep 17 00:00:00 2001
From: Garrett Cooper <yanegomi@gmail.com>
Date: Thu, 8 Aug 2013 18:26:53 -0700
Subject: [PATCH] Handle invalid modes properly

Sponsored-by: EMC Isilon
---
 sys/kern/vfs_syscalls.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index a004ea0..9350821 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -2094,6 +2094,9 @@ kern_accessat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
 	struct nameidata nd;
 	int error;
 
+	if (amode & ~(F_OK | R_OK | W_OK | X_OK))
+		return (EINVAL);
+
 	/*
 	 * Create and modify a temporary credential instead of one that
 	 * is potentially shared.
-- 
1.8.3.4



>Release-Note:
>Audit-Trail:

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup@FreeBSD.org, Garrett Cooper <yaneurabeya@gmail.com>
Cc:  
Subject: Re: kern/181155: [libc] [patch] *access*(2) does not handle invalid
 amodes properly
Date: Fri, 18 Apr 2014 10:18:56 -0700

     Just as a note: I need to add something to the manpage for all
 affected system calls for this; mknodat and a few other system calls
 will need manpage updates .. need to evaluate all of the system calls
 to get a full list of everything affected.
 Thanks!
 -Garrett

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup@freebsd.org, Garrett Cooper <yaneurabeya@gmail.com>
Cc:  
Subject: Re: kern/181155: [libc] [patch] *access*(2) does not handle invalid
 amodes properly
Date: Fri, 18 Apr 2014 10:23:08 -0700

 On Fri, Apr 18, 2014 at 10:18 AM, Garrett Cooper <yaneurabeya@gmail.com> wrote:
 >     Just as a note: I need to add something to the manpage for all
 > affected system calls for this; mknodat and a few other system calls
 > will need manpage updates .. need to evaluate all of the system calls
 > to get a full list of everything affected.
 
     And one more thing: fixing this will make FreeBSD more POSIX
 compliant with this system call (
 http://pubs.opengroup.org/onlinepubs/009695299/functions/access.html
 ), will match the behavior on Linux and NetBSD at least:
 
 The access() function may fail if:
 
 [EINVAL]The value of the amode argument is invalid.
 
 Thanks!
 -Garrett
>Unformatted:
