The patch titled sys_times() fix return values has been added to the -mm tree. Its filename is sys_times-fix-return-values.patch *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: sys_times() fix return values From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> David Brown points out that compat_sys_times() (and sys_times()) can return arbitrary 32-bit (or 64-bit values). If these happen to be negative (jiffy wrap, or before INITIAL_JIFFIES) then libc will interpret this as an error and will return -1 to the libc user and will set errno. The manpage for times(2) says: times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. For Linux 2.4 and earlier this point is the moment the system was booted. Since Linux 2.6, this point is (2^32/HZ) - 300 (i.e., about 429 million) seconds before system boot time. The return value may overflow the possible range of type clock_t. On error, (clock_t) -1 is returned, and errno is set appro- priately. We can fix this by masking the return value down to a 31-bit (63-bit) value. Also, let's correct for INTIAL_JIFFIES - this isn't a detail which should be exposed to userspace. Unfortunately this change can break userspace. If a program was (correctly) doing: unsigned long start = times(...); ... unsigned long end = times(...); unsigned long delta = end - start; then `delta' can be grossly wrong if we wrapped in the interval. Instead userspace will need to mask `delta' by 0x7fffffff (0x7fffffffffffffff) to get the correct number. But userspace was already busted in the presence of wraparound, due to glibc's convert-to-negative-one behaviour. Given all this stuff, the return value from sys_times() doesn't seem a particularly useful or reliable kernel interface. Cc: David Brown <lkml@xxxxxxxxxx> Cc: Ulrich Drepper <drepper@xxxxxxxxxx> Cc: Michael Kerrisk <mtk-manpages@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/compat.c | 3 ++- kernel/sys.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff -puN kernel/sys.c~sys_times-fix-return-values kernel/sys.c --- a/kernel/sys.c~sys_times-fix-return-values +++ a/kernel/sys.c @@ -897,7 +897,8 @@ asmlinkage long sys_times(struct tms __u if (copy_to_user(tbuf, &tmp, sizeof(struct tms))) return -EFAULT; } - return (long) jiffies_64_to_clock_t(get_jiffies_64()); + return jiffies_64_to_clock_t((get_jiffies_64() + INITIAL_JIFFIES) & + LONG_MAX); } /* diff -puN kernel/compat.c~sys_times-fix-return-values kernel/compat.c --- a/kernel/compat.c~sys_times-fix-return-values +++ a/kernel/compat.c @@ -162,7 +162,8 @@ asmlinkage long compat_sys_times(struct if (copy_to_user(tbuf, &tmp, sizeof(tmp))) return -EFAULT; } - return compat_jiffies_to_clock_t(jiffies); + return compat_jiffies_to_clock_t((jiffies + INITIAL_JIFFIES) & + LONG_MAX); } /* _ Patches currently in -mm which might be from akpm@xxxxxxxxxxxxxxxxxxxx are origin.patch proc-fix-proc_kill_inodes-to-kill-dentries-on-all-proc-superblocks-checkpatch-fixes.patch acpi-make-acpi_procfs-default-to-y.patch acpi-enable-c3-power-state-on-dell-inspiron-8200-fix.patch acpi-add-reboot-mechanism.patch small-acpica-extension-to-be-able-to-store-the-name-of-fix.patch git-alsa.patch working-3d-dri-intel-agpko-resume-for-i815-chip.patch git-arm.patch git-arm-fixup.patch agk-dm-dm-ioctl-move-compat-code-fix.patch git-hwmon.patch ia64-slim-down-__clear_bit_unlock-checkpatch-fixes.patch elantech-touchpad-driver-fix.patch git-kvm.patch git-libata-all.patch drivers-ata-libata-ehc-fix-printk-warning.patch pata_hpt37x-fix-outstanding-bug-reports-on-the-hpt374-and-37x-cable-detect-checkpatch-fixes.patch ide-arm-hack.patch git-mtd-fix.patch lmc_ioctl-dont-return-with-locks-held-fix.patch git-netdev-all.patch ucc_geth-fix-build-break-introduced-by-commit-09f75cd7bf13720738e6a196cc0107ce9a5bd5a0-checkpatch-fixes.patch update-smc91x-driver-with-arm-versatile-board-info.patch bluetooth-uninlining.patch git-nfsd-fixup.patch quirk_vialatency-omit-reading-pci-revision-id-checkpatch-fixes.patch fix-build-breakage-if-sysfs-fix.patch wd7000-broke.patch ips-trim-trailing-whitespace-checkpatch-fixes.patch scsi-gdth-kill-unneeded-irq-argument-checkpatch-fixes.patch scsi-fix-bugs-and-canonicalize-ncr5380_intr-drivers-checkpatch-fixes.patch git-unionfs.patch vfs-swap-do_ioctl-and-vfs_ioctl-names-fix.patch git-wireless.patch jiffies_round-jiffies_round_relative-conversion-rt2x00-checkpatch-fixes.patch git-ipwireless-ipwireless_cs_tty-warning-fix.patch git-x86.patch git-x86-fixup.patch oprofile-op_model_athalonc-support-for-amd-family10h-barcelona-performance-counters-checkpatch-fixes.patch i386-and-x86_64-randomize-brk-fix.patch x86-arch_register_cpu-section-fix.patch mips-undo-locking-on-error-path-returns-checkpatch-fixes.patch pidns-place-under-config_experimental-checkpatch-fixes.patch fix-64kb-blocksize-in-ext3-directories-checkpatch-fixes.patch file-capabilities-allow-sigcont-within-session-v2-checkpatch-fixes.patch x86-disable-preemption-in-delay_tsc.patch pagecache-zeroing-zero_user_segment-zero_user_segments-and-zero_user-fix.patch pagecache-zeroing-zero_user_segment-zero_user_segments-and-zero_user-fix-2.patch i386-resolve-dependency-of-asm-i386-pgtableh-on-highmemh-checkpatch-fixes.patch slub-fix-coding-style-violations-checkpatch-fixes.patch slub-provide-unique-end-marker-for-each-slab-fix.patch slub-do-our-own-locking-via-slab_lock-and-slab_unlock-checkpatch-fixes.patch bufferhead-revert-constructor-removal-checkpatch-fixes.patch maps4-make-page-monitoring-proc-file-optional-fix.patch hugetlb-split-alloc_huge_page-into-private-and-shared-components-checkpatch-fixes.patch vmscan-give-referenced-active-and-unmapped-pages-a-second-trip-around-the-lru.patch vm-dont-run-touch_buffer-during-buffercache-lookups.patch pm-qos-infrastructure-and-interface.patch pm-qos-infrastructure-and-interface-static-initialization-with-blocking-notifiers.patch cris-build-fixes-atomich-needs-compilerh-fix.patch cris-build-fixes-update-eth_v10c-ethernet-driver-fix.patch cris-build-fixes-fix-mtdramh-checkpatch-fixes.patch cris-build-fixes-fixes-in-arch-cris-kernel-timec-checkpatch-fixes.patch cris-remove-mtd_amstd-and-mtd_obsolete_chips-take-two-checkpatch-fixes.patch uml-get-rid-of-asmlinkage-checkpatch-fixes.patch uml-improve-detection-of-host-cmov-checkpatch-fixes.patch uml-further-bugsc-tidying-checkpatch-fixes.patch deprecate-smbfs-in-favour-of-cifs.patch procfs-detect-duplicate-names.patch kernel-printkc-concerns-about-the-console-handover.patch fix-versus-precedence-in-various-places-checkpatch-fixes.patch pie-executable-randomization.patch pie-executable-randomization-checkpatch-fixes.patch riscom8-fix-smp-brokenness-fix.patch use-macros-instead-of-task_-flags-checkpatch-fixes.patch sound-oss-pss-set_io_base-always-returns-success-mark-it-void-checkpatch-fixes.patch remove-warnings-for-longstanding-conditions-fix.patch parallel-port-convert-port_mutex-to-the-mutex-api-checkpatch-fixes.patch remove-support-for-un-needed-_extratext-section-checkpatch-fixes.patch allow-auto-destruction-of-loop-devices-checkpatch-fixes.patch remove-__attribute_used__-checkpatch-fixes.patch read_current_time-cleanups.patch sync_sb_inodes-propagate-errors.patch 64-bit-i_version-afs-fixes.patch kill-filp_open-checkpatch-fixes.patch rename-open_namei-to-open_pathname-fix.patch r-o-bind-mounts-elevate-write-count-during-entire-ncp_ioctl-fix.patch r-o-bind-mounts-elevate-write-count-for-do_utimes.patch r-o-bind-mounts-elevate-write-count-for-some-ioctls-checkpatch-fixes.patch r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files.patch r-o-bind-mounts-nfs-check-mnt-instead-of-superblock-directly-checkpatch-fixes.patch slab-api-remove-useless-ctor-parameter-and-reorder-parameters-vs-revoke.patch revoke-wire-up-i386-system-calls.patch revoke-vs-git-block.patch cgroup-simplify-space-stripping-fix.patch memory-controller-memory-accounting-v7.patch memory-controller-add-per-container-lru-and-reclaim-v7.patch memory-controller-oom-handling-v7.patch memory-controller-add-switch-to-control-what-type-of-pages-to-limit-v7.patch memcontrol-move-oom-task-exclusion-to-tasklist.patch memory-cgroup-enhancements-add-status-accounting-function-for-memory-cgroup-checkpatch-fixes.patch memory-cgroup-enhancements-add-status-accounting-function-for-memory-cgroup-fix-1.patch memory-cgroup-enhancements-add-status-accounting-function-for-memory-cgroup-uninlining.patch memory-cgroup-enhancements-add-status-accounting-function-for-memory-cgroup-fix-2.patch memory-cgroup-enhancements-add-memorystat-file-checkpatch-fixes.patch drivers-edac-add-marvell-mv64x60-driver-fix.patch introduce-flags-for-reserve_bootmem-checkpatch-fixes.patch iget-stop-affs-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-efs-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-ext2-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-ext3-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-freevxfs-from-using-iget-and-read_inode-checkpatch-fixes.patch iget-stop-the-minix-filesystem-from-using-iget-and-checkpatch-fixes.patch iget-stop-procfs-from-using-iget-and-read_inode-checkpatch-fixes.patch iget-stop-qnx4-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-romfs-from-using-iget-and-read_inode-checkpatch-fixes.patch iget-stop-the-sysv-filesystem-from-using-iget-and-checkpatch-fixes.patch iget-stop-ufs-from-using-iget-and-read_inode-try-checkpatch-fixes.patch iget-stop-hostfs-from-using-iget-and-read_inode-checkpatch-fixes.patch dhowells-broke-unionfs.patch embed-a-struct-path-into-struct-nameidata-instead-of-nd-dentrymnt-checkpatch-fixes.patch one-less-parameter-to-__d_path-checkpatch-fixes.patch d_path-use-struct-path-in-struct-avc_audit_data-checkpatch-fixes.patch d_path-make-get_dcookie-use-a-struct-path-argument-checkpatch-fixes.patch use-struct-path-in-struct-svc_export-checkpatch-fixes.patch make-copy_from_user_inatomic-not-zero-the-tail-on-i386-vs-reiser4.patch reiser4.patch jens-broke-reiser4patch-added-to-mm-tree.patch page-owner-tracking-leak-detector.patch nr_blockdev_pages-in_interrupt-warning.patch slab-leaks3-default-y.patch profile-likely-unlikely-macros-fix.patch put_bh-debug.patch kmap_atomic-debugging.patch shrink_slab-handle-bad-shrinkers.patch getblk-handle-2tb-devices.patch w1-build-fix.patch sys_times-fix-return-values.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html