[PATCH] Shrink sys_utime()



All checks in sys_utime() and do_utimes() are duplicated as well as a
comment. sys_utime() will now use do_utimes() after getting times from
userspace and projecting them to struct timeval [2].

__kernel_time_t seems to be long on all archs.

Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---

fs/utimes.c | 90 ++++++++++++++++--------------------------------------------
1 file changed, 25 insertions(+), 65 deletions(-)

--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -6,71 +6,6 @@ #include <linux/utime.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>

-#ifdef __ARCH_WANT_SYS_UTIME
-
-/*
- * sys_utime() can be implemented in user-level using sys_utimes().
- * Is this for backwards compatibility? If so, why not move it
- * into the appropriate arch directory (for those architectures that
- * need it).
- */
-
-/* If times==NULL, set access and modification to current time,
- * must be owner or have write permission.
- * Else, update from *times, must be owner or super user.
- */
-asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * times)
-{
- int error;
- struct nameidata nd;
- struct inode * inode;
- struct iattr newattrs;
-
- error = user_path_walk(filename, &nd);
- if (error)
- goto out;
- inode = nd.dentry->d_inode;
-
- error = -EROFS;
- if (IS_RDONLY(inode))
- goto dput_and_out;
-
- /* Don't worry, the checks are done in inode_change_ok() */
- newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
- if (times) {
- error = -EPERM;
- if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
- goto dput_and_out;
-
- error = get_user(newattrs.ia_atime.tv_sec, &times->actime);
- newattrs.ia_atime.tv_nsec = 0;
- if (!error)
- error = get_user(newattrs.ia_mtime.tv_sec, &times->modtime);
- newattrs.ia_mtime.tv_nsec = 0;
- if (error)
- goto dput_and_out;
-
- newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
- } else {
- error = -EACCES;
- if (IS_IMMUTABLE(inode))
- goto dput_and_out;
-
- if (current->fsuid != inode->i_uid &&
- (error = vfs_permission(&nd, MAY_WRITE)) != 0)
- goto dput_and_out;
- }
- mutex_lock(&inode->i_mutex);
- error = notify_change(nd.dentry, &newattrs);
- mutex_unlock(&inode->i_mutex);
-dput_and_out:
- path_release(&nd);
-out:
- return error;
-}
-
-#endif
-
/* If times==NULL, set access and modification to current time,
* must be owner or have write permission.
* Else, update from *times, must be owner or super user.
@@ -122,6 +57,31 @@ out:
return error;
}

+#ifdef __ARCH_WANT_SYS_UTIME
+
+/*
+ * sys_utime() can be implemented in user-level using sys_utimes().
+ * Is this for backwards compatibility? If so, why not move it
+ * into the appropriate arch directory (for those architectures that
+ * need it).
+ */
+asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * utimes)
+{
+ struct timeval times[2];
+
+ if (utimes) {
+ if (get_user(times[0].tv_sec, &utimes->actime))
+ return -EFAULT;
+ times[0].tv_usec = 0;
+ if (get_user(times[1].tv_sec, &utimes->modtime))
+ return -EFAULT;
+ times[1].tv_usec = 0;
+ }
+ return do_utimes(AT_FDCWD, filename, utimes ? times : NULL);
+}
+
+#endif
+
asmlinkage long sys_futimesat(int dfd, char __user *filename, struct timeval __user *utimes)
{
struct timeval times[2];

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: groups vs users
    ... , Dave Stratford wrote: ... owner would be the owner of the directory and NOT the primary ... The '2xxx' permission on a directory has been described upthread. ... The not-very-useful permissions of 2740 (SGID, but without the execute ...
    (comp.os.linux.setup)
  • Re: Object permissions
    ... you grant modify permission on the qryAttendanceActual query. ... trying to change the owner to a group or an individual, ... the query, they can actually open the query once the sql is set. ...
    (microsoft.public.access.security)
  • Re: Plutos OK
    ... copyright holder, to avoid a copyrighted item from becoming an orphan, thus ... making it impossible to legally get permission to copy. ... current owner is unknown. ... the permission of the copyright holder, ...
    (sci.space.history)
  • Re: Object permissions
    ... only the owner can set the RWOP property on a query. ... Once I removed that line from the sql, ... you grant modify permission on the qryAttendanceActual query. ...
    (microsoft.public.access.security)
  • Re: Object permissions
    ... objQDF.SQL= strSQLAttendance with the error about not having necessary ... implicit 'read and modify' permissions on the query. ... If I set up a new query with this user or their group as the owner, ... Especially when this code should work with only the modify permission ...
    (microsoft.public.access.security)