1. 03 10月, 2020 1 次提交
  2. 08 8月, 2020 1 次提交
  3. 28 7月, 2020 1 次提交
  4. 20 7月, 2020 2 次提交
  5. 14 7月, 2020 4 次提交
    • K
      fs: Add receive_fd() wrapper for __receive_fd() · deefa7f3
      Kees Cook 提交于
      For both pidfd and seccomp, the __user pointer is not used. Update
      __receive_fd() to make writing to ufd optional via a NULL check. However,
      for the receive_fd_user() wrapper, ufd is NULL checked so an -EFAULT
      can be returned to avoid changing the SCM_RIGHTS interface behavior. Add
      new wrapper receive_fd() for pidfd and seccomp that does not use the ufd
      argument. For the new helper, the allocated fd needs to be returned on
      success. Update the existing callers to handle it.
      
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: NSargun Dhillon <sargun@sargun.me>
      Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      deefa7f3
    • K
      fs: Move __scm_install_fd() to __receive_fd() · 66590610
      Kees Cook 提交于
      In preparation for users of the "install a received file" logic outside
      of net/ (pidfd and seccomp), relocate and rename __scm_install_fd() from
      net/core/scm.c to __receive_fd() in fs/file.c, and provide a wrapper
      named receive_fd_user(), as future patches will change the interface
      to __receive_fd().
      
      Additionally add a comment to fd_install() as a counterpoint to how
      __receive_fd() interacts with fput().
      
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Dmitry Kadashev <dkadashev@gmail.com>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Sargun Dhillon <sargun@sargun.me>
      Cc: Ido Schimmel <idosch@idosch.org>
      Cc: Ioana Ciornei <ioana.ciornei@nxp.com>
      Cc: linux-fsdevel@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Reviewed-by: NSargun Dhillon <sargun@sargun.me>
      Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      66590610
    • K
      net/scm: Regularize compat handling of scm_detach_fds() · c0029de5
      Kees Cook 提交于
      Duplicate the cleanups from commit 2618d530 ("net/scm: cleanup
      scm_detach_fds") into the compat code.
      
      Replace open-coded __receive_sock() with a call to the helper.
      
      Move the check added in commit 1f466e1f ("net: cleanly handle kernel
      vs user buffers for ->msg_control") to before the compat call, even
      though it should be impossible for an in-kernel call to also be compat.
      
      Correct the int "flags" argument to unsigned int to match fd_install()
      and similar APIs.
      
      Regularize any remaining differences, including a whitespace issue,
      a checkpatch warning, and add the check from commit 6900317f ("net,
      scm: fix PaX detected msg_controllen overflow in scm_detach_fds") which
      fixed an overflow unique to 64-bit. To avoid confusion when comparing
      the compat handler to the native handler, just include the same check
      in the compat handler.
      
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Sargun Dhillon <sargun@sargun.me>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: netdev@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      c0029de5
    • K
      net/compat: Add missing sock updates for SCM_RIGHTS · d9539752
      Kees Cook 提交于
      Add missed sock updates to compat path via a new helper, which will be
      used more in coming patches. (The net/core/scm.c code is left as-is here
      to assist with -stable backports for the compat path.)
      
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Sargun Dhillon <sargun@sargun.me>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: stable@vger.kernel.org
      Fixes: 48a87cc2 ("net: netprio: fd passed in SCM_RIGHTS datagram not set correctly")
      Fixes: d8429506 ("net: net_cls: fd passed in SCM_RIGHTS datagram not set correctly")
      Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      d9539752
  6. 02 6月, 2020 1 次提交
  7. 21 5月, 2020 3 次提交
    • A
      get rid of compat_mc_setsockopt() · bbced07d
      Al Viro 提交于
      not used anymore
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      bbced07d
    • A
      get rid of compat_mc_getsockopt() · 0dfe6581
      Al Viro 提交于
      now we can do MCAST_MSFILTER in compat ->getsockopt() without
      playing silly buggers with copying things back and forth.
      We can form a native struct group_filter (sans the variable-length
      tail) on stack, pass that + pointer to the tail of original request
      to the helper doing the bulk of the work, then do the rest of
      copyout - same as the native getsockopt() does.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      0dfe6581
    • A
      lift compat definitions of mcast [sg]etsockopt requests into net/compat.h · 63287de6
      Al Viro 提交于
      We want to get rid of compat_mc_[sg]etsockopt() and to have that stuff
      handled without compat_alloc_user_space(), extra copying through
      userland, etc.  To do that we'll need ipv4 and ipv6 instances of
      ->compat_[sg]etsockopt() to manipulate the 32bit variants of mcast
      requests, so we need to move the definitions of those out of net/compat.c
      and into a public header.
      
      This patch just does a mechanical move to include/net/compat.h
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      63287de6
  8. 12 5月, 2020 1 次提交
    • C
      net: cleanly handle kernel vs user buffers for ->msg_control · 1f466e1f
      Christoph Hellwig 提交于
      The msg_control field in struct msghdr can either contain a user
      pointer when used with the recvmsg system call, or a kernel pointer
      when used with sendmsg.  To complicate things further kernel_recvmsg
      can stuff a kernel pointer in and then use set_fs to make the uaccess
      helpers accept it.
      
      Replace it with a union of a kernel pointer msg_control field, and
      a user pointer msg_control_user one, and allow kernel_recvmsg operate
      on a proper kernel pointer using a bitfield to override the normal
      choice of a user pointer for recvmsg.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1f466e1f
  9. 10 3月, 2020 1 次提交
  10. 15 11月, 2019 1 次提交
    • A
      y2038: socket: use __kernel_old_timespec instead of timespec · df1b4ba9
      Arnd Bergmann 提交于
      The 'timespec' type definition and helpers like ktime_to_timespec()
      or timespec64_to_timespec() should no longer be used in the kernel so
      we can remove them and avoid introducing y2038 issues in new code.
      
      Change the socket code that needs to pass a timespec to user space for
      backward compatibility to use __kernel_old_timespec instead.  This type
      has the same layout but with a clearer defined name.
      
      Slightly reformat tcp_recv_timestamp() for consistency after the removal
      of timespec64_to_timespec().
      Acked-by: NDeepa Dinamani <deepa.kernel@gmail.com>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      df1b4ba9
  11. 01 6月, 2019 1 次提交
  12. 21 5月, 2019 1 次提交
  13. 20 4月, 2019 1 次提交
  14. 04 3月, 2019 1 次提交
    • B
      net: fixup address-space warnings in compat_mc_{get,set}sockopt() · 46d84110
      Ben Dooks 提交于
      Add __user attributes in some of the casts in this function to avoid
      the following sparse warnings:
      
      net/compat.c:592:57: warning: cast removes address space of expression
      net/compat.c:592:57: warning: incorrect type in initializer (different address spaces)
      net/compat.c:592:57:    expected struct compat_group_req [noderef] <asn:1>*gr32
      net/compat.c:592:57:    got void *<noident>
      net/compat.c:613:65: warning: cast removes address space of expression
      net/compat.c:613:65: warning: incorrect type in initializer (different address spaces)
      net/compat.c:613:65:    expected struct compat_group_source_req [noderef] <asn:1>*gsr32
      net/compat.c:613:65:    got void *<noident>
      net/compat.c:634:60: warning: cast removes address space of expression
      net/compat.c:634:60: warning: incorrect type in initializer (different address spaces)
      net/compat.c:634:60:    expected struct compat_group_filter [noderef] <asn:1>*gf32
      net/compat.c:634:60:    got void *<noident>
      net/compat.c:672:52: warning: cast removes address space of expression
      net/compat.c:672:52: warning: incorrect type in initializer (different address spaces)
      net/compat.c:672:52:    expected struct compat_group_filter [noderef] <asn:1>*gf32
      net/compat.c:672:52:    got void *<noident>
      Signed-off-by: NBen Dooks <ben.dooks@codethink.co.uk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      46d84110
  15. 23 2月, 2019 1 次提交
  16. 07 2月, 2019 1 次提交
    • A
      y2038: syscalls: rename y2038 compat syscalls · 8dabe724
      Arnd Bergmann 提交于
      A lot of system calls that pass a time_t somewhere have an implementation
      using a COMPAT_SYSCALL_DEFINEx() on 64-bit architectures, and have
      been reworked so that this implementation can now be used on 32-bit
      architectures as well.
      
      The missing step is to redefine them using the regular SYSCALL_DEFINEx()
      to get them out of the compat namespace and make it possible to build them
      on 32-bit architectures.
      
      Any system call that ends in 'time' gets a '32' suffix on its name for
      that version, while the others get a '_time32' suffix, to distinguish
      them from the normal version, which takes a 64-bit time argument in the
      future.
      
      In this step, only 64-bit architectures are changed, doing this rename
      first lets us avoid touching the 32-bit architectures twice.
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      8dabe724
  17. 04 2月, 2019 3 次提交
  18. 04 1月, 2019 1 次提交
    • L
      Remove 'type' argument from access_ok() function · 96d4f267
      Linus Torvalds 提交于
      Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
      of the user address range verification function since we got rid of the
      old racy i386-only code to walk page tables by hand.
      
      It existed because the original 80386 would not honor the write protect
      bit when in kernel mode, so you had to do COW by hand before doing any
      user access.  But we haven't supported that in a long time, and these
      days the 'type' argument is a purely historical artifact.
      
      A discussion about extending 'user_access_begin()' to do the range
      checking resulted this patch, because there is no way we're going to
      move the old VERIFY_xyz interface to that model.  And it's best done at
      the end of the merge window when I've done most of my merges, so let's
      just get this done once and for all.
      
      This patch was mostly done with a sed-script, with manual fix-ups for
      the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
      
      There were a couple of notable cases:
      
       - csky still had the old "verify_area()" name as an alias.
      
       - the iter_iov code had magical hardcoded knowledge of the actual
         values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
         really used it)
      
       - microblaze used the type argument for a debug printout
      
      but other than those oddities this should be a total no-op patch.
      
      I tried to fix up all architectures, did fairly extensive grepping for
      access_ok() uses, and the changes are trivial, but I may have missed
      something.  Any missed conversion should be trivially fixable, though.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      96d4f267
  19. 02 1月, 2019 1 次提交
    • D
      sock: Make sock->sk_stamp thread-safe · 3a0ed3e9
      Deepa Dinamani 提交于
      Al Viro mentioned (Message-ID
      <20170626041334.GZ10672@ZenIV.linux.org.uk>)
      that there is probably a race condition
      lurking in accesses of sk_stamp on 32-bit machines.
      
      sock->sk_stamp is of type ktime_t which is always an s64.
      On a 32 bit architecture, we might run into situations of
      unsafe access as the access to the field becomes non atomic.
      
      Use seqlocks for synchronization.
      This allows us to avoid using spinlocks for readers as
      readers do not need mutual exclusion.
      
      Another approach to solve this is to require sk_lock for all
      modifications of the timestamps. The current approach allows
      for timestamps to have their own lock: sk_stamp_lock.
      This allows for the patch to not compete with already
      existing critical sections, and side effects are limited
      to the paths in the patch.
      
      The addition of the new field maintains the data locality
      optimizations from
      commit 9115e8cd ("net: reorganize struct sock for better data
      locality")
      
      Note that all the instances of the sk_stamp accesses
      are either through the ioctl or the syscall recvmsg.
      Signed-off-by: NDeepa Dinamani <deepa.kernel@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3a0ed3e9
  20. 18 12月, 2018 1 次提交
    • A
      y2038: socket: Add compat_sys_recvmmsg_time64 · e11d4284
      Arnd Bergmann 提交于
      recvmmsg() takes two arguments to pointers of structures that differ
      between 32-bit and 64-bit architectures: mmsghdr and timespec.
      
      For y2038 compatbility, we are changing the native system call from
      timespec to __kernel_timespec with a 64-bit time_t (in another patch),
      and use the existing compat system call on both 32-bit and 64-bit
      architectures for compatibility with traditional 32-bit user space.
      
      As we now have two variants of recvmmsg() for 32-bit tasks that are both
      different from the variant that we use on 64-bit tasks, this means we
      also require two compat system calls!
      
      The solution I picked is to flip things around: The existing
      compat_sys_recvmmsg() call gets moved from net/compat.c into net/socket.c
      and now handles the case for old user space on all architectures that
      have set CONFIG_COMPAT_32BIT_TIME.  A new compat_sys_recvmmsg_time64()
      call gets added in the old place for 64-bit architectures only, this
      one handles the case of a compat mmsghdr structure combined with
      __kernel_timespec.
      
      In the indirect sys_socketcall(), we now need to call either
      do_sys_recvmmsg() or __compat_sys_recvmmsg(), depending on what kind of
      architecture we are on. For compat_sys_socketcall(), no such change is
      needed, we always call __compat_sys_recvmmsg().
      
      I decided to not add a new SYS_RECVMMSG_TIME64 socketcall: Any libc
      implementation for 64-bit time_t will need significant changes including
      an updated asm/unistd.h, and it seems better to consistently use the
      separate syscalls that configuration, leaving the socketcall only for
      backward compatibility with 32-bit time_t based libc.
      
      The naming is asymmetric for the moment, so both existing syscalls
      entry points keep their names, while the new ones are recvmmsg_time32
      and compat_recvmmsg_time64 respectively. I expect that we will rename
      the compat syscalls later as we start using generated syscall tables
      everywhere and add these entry points.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      e11d4284
  21. 29 8月, 2018 1 次提交
    • A
      y2038: socket: Change recvmmsg to use __kernel_timespec · c2e6c856
      Arnd Bergmann 提交于
      This converts the recvmmsg() system call in all its variations to use
      'timespec64' internally for its timeout, and have a __kernel_timespec64
      argument in the native entry point. This lets us change the type to use
      64-bit time_t at a later point while using the 32-bit compat system call
      emulation for existing user space.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      c2e6c856
  22. 27 8月, 2018 1 次提交
    • A
      y2038: globally rename compat_time to old_time32 · 9afc5eee
      Arnd Bergmann 提交于
      Christoph Hellwig suggested a slightly different path for handling
      backwards compatibility with the 32-bit time_t based system calls:
      
      Rather than simply reusing the compat_sys_* entry points on 32-bit
      architectures unchanged, we get rid of those entry points and the
      compat_time types by renaming them to something that makes more sense
      on 32-bit architectures (which don't have a compat mode otherwise),
      and then share the entry points under the new name with the 64-bit
      architectures that use them for implementing the compatibility.
      
      The following types and interfaces are renamed here, and moved
      from linux/compat_time.h to linux/time32.h:
      
      old				new
      ---				---
      compat_time_t			old_time32_t
      struct compat_timeval		struct old_timeval32
      struct compat_timespec		struct old_timespec32
      struct compat_itimerspec	struct old_itimerspec32
      ns_to_compat_timeval()		ns_to_old_timeval32()
      get_compat_itimerspec64()	get_old_itimerspec32()
      put_compat_itimerspec64()	put_old_itimerspec32()
      compat_get_timespec64()		get_old_timespec32()
      compat_put_timespec64()		put_old_timespec32()
      
      As we already have aliases in place, this patch addresses only the
      instances that are relevant to the system call interface in particular,
      not those that occur in device drivers and other modules. Those
      will get handled separately, while providing the 64-bit version
      of the respective interfaces.
      
      I'm not renaming the timex, rusage and itimerval structures, as we are
      still debating what the new interface will look like, and whether we
      will need a replacement at all.
      
      This also doesn't change the names of the syscall entry points, which can
      be done more easily when we actually switch over the 32-bit architectures
      to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
      SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
      Suggested-by: NChristoph Hellwig <hch@infradead.org>
      Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      9afc5eee
  23. 07 8月, 2018 1 次提交
  24. 28 4月, 2018 1 次提交
    • L
      net: support compat 64-bit time in {s,g}etsockopt · 988bf724
      Lance Richardson 提交于
      For the x32 ABI, struct timeval has two 64-bit fields. However
      the kernel currently interprets the user-space values used for
      the SO_RCVTIMEO and SO_SNDTIMEO socket options as having a pair
      of 32-bit fields.
      
      When the seconds portion of the requested timeout is less than 2**32,
      the seconds portion of the effective timeout is correct but the
      microseconds portion is zero.  When the seconds portion of the
      requested timeout is zero and the microseconds portion is non-zero,
      the kernel interprets the timeout as zero (never timeout).
      
      Fix by using 64-bit time for SO_RCVTIMEO/SO_SNDTIMEO as required
      for the ABI.
      
      The code included below demonstrates the problem.
      
      Results before patch:
          $ gcc -m64 -Wall -O2 -o socktmo socktmo.c && ./socktmo
          recv time: 2.008181 seconds
          send time: 2.015985 seconds
      
          $ gcc -m32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
          recv time: 2.016763 seconds
          send time: 2.016062 seconds
      
          $ gcc -mx32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
          recv time: 1.007239 seconds
          send time: 1.023890 seconds
      
      Results after patch:
          $ gcc -m64 -O2 -Wall -o socktmo socktmo.c && ./socktmo
          recv time: 2.010062 seconds
          send time: 2.015836 seconds
      
          $ gcc -m32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
          recv time: 2.013974 seconds
          send time: 2.015981 seconds
      
          $ gcc -mx32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
          recv time: 2.030257 seconds
          send time: 2.013383 seconds
      
       #include <stdio.h>
       #include <stdlib.h>
       #include <sys/socket.h>
       #include <sys/types.h>
       #include <sys/time.h>
      
       void checkrc(char *str, int rc)
       {
               if (rc >= 0)
                       return;
      
               perror(str);
               exit(1);
       }
      
       static char buf[1024];
       int main(int argc, char **argv)
       {
               int rc;
               int socks[2];
               struct timeval tv;
               struct timeval start, end, delta;
      
               rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socks);
               checkrc("socketpair", rc);
      
               /* set timeout to 1.999999 seconds */
               tv.tv_sec = 1;
               tv.tv_usec = 999999;
               rc = setsockopt(socks[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
               rc = setsockopt(socks[0], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
               checkrc("setsockopt", rc);
      
               /* measure actual receive timeout */
               gettimeofday(&start, NULL);
               rc = recv(socks[0], buf, sizeof buf, 0);
               gettimeofday(&end, NULL);
               timersub(&end, &start, &delta);
      
               printf("recv time: %ld.%06ld seconds\n",
                      (long)delta.tv_sec, (long)delta.tv_usec);
      
               /* fill send buffer */
               do {
                       rc = send(socks[0], buf, sizeof buf, 0);
               } while (rc > 0);
      
               /* measure actual send timeout */
               gettimeofday(&start, NULL);
               rc = send(socks[0], buf, sizeof buf, 0);
               gettimeofday(&end, NULL);
               timersub(&end, &start, &delta);
      
               printf("send time: %ld.%06ld seconds\n",
                      (long)delta.tv_sec, (long)delta.tv_usec);
               exit(0);
       }
      
      Fixes: 515c7af8 ("x32: Use compat shims for {g,s}etsockopt")
      Reported-by: NGopal RajagopalSai <gopalsr83@gmail.com>
      Signed-off-by: NLance Richardson <lance.richardson.net@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      988bf724
  25. 03 4月, 2018 8 次提交