1. 13 Apr, 2020 30 commits
  2. 02 Apr, 2020 10 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.9.218 · a5ad06fc
      Greg Kroah-Hartman authored
      a5ad06fc
    • disconnect3d's avatar
      perf map: Fix off by one in strncpy() size argument · 6d5fd9db
      disconnect3d authored
      commit db2c5494 upstream.
      
      This patch fixes an off-by-one error in strncpy size argument in
      tools/perf/util/map.c. The issue is that in:
      
              strncmp(filename, "/system/lib/", 11)
      
      the passed string literal: "/system/lib/" has 12 bytes (without the NULL
      byte) and the passed size argument is 11. As a result, the logic won't
      match the ending "/" byte and will pass filepaths that are stored in
      other directories e.g. "/system/libmalicious/bin" or just
      "/system/libmalicious".
      
      This functionality seems to be present only on Android. I assume the
      /system/ directory is only writable by the root user, so I don't think
      this bug has much (or any) security impact.
      
      Fixes: eca81836 ("perf tools: Add automatic remapping of Android libraries")
      Signed-off-by: default avatardisconnect3d <dominik.b.czarnota@gmail.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Changbin Du <changbin.du@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Keeping <john@metanate.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Michael Lentine <mlentine@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200309104855.3775-1-dominik.b.czarnota@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d5fd9db
    • Ilie Halip's avatar
      arm64: alternative: fix build with clang integrated assembler · fd08eda5
      Ilie Halip authored
      commit 6f5459da upstream.
      
      Building an arm64 defconfig with clang's integrated assembler, this error
      occurs:
          <instantiation>:2:2: error: unrecognized instruction mnemonic
           _ASM_EXTABLE 9999b, 9f
           ^
          arch/arm64/mm/cache.S:50:1: note: while in macro instantiation
          user_alt 9f, "dc cvau, x4", "dc civac, x4", 0
          ^
      
      While GNU as seems fine with case-sensitive macro instantiations, clang
      doesn't, so use the actual macro name (_asm_extable) as in the rest of
      the file.
      
      Also checked that the generated assembly matches the GCC output.
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Fixes: 290622ef ("arm64: fix "dc cvau" cache operation on errata-affected core")
      Link: https://github.com/ClangBuiltLinux/linux/issues/924Signed-off-by: default avatarIlie Halip <ilie.halip@gmail.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fd08eda5
    • Marek Vasut's avatar
      net: ks8851-ml: Fix IO operations, again · 8b1d5cd9
      Marek Vasut authored
      commit 8262e6f9 upstream.
      
      This patch reverts 58292104 ("net: ks8851-ml: Fix 16-bit IO operation")
      and edacb098 ("net: ks8851-ml: Fix 16-bit data access"), because it
      turns out these were only necessary due to buggy hardware. This patch adds
      a check for such a buggy hardware to prevent any such mistakes again.
      
      While working further on the KS8851 driver, it came to light that the
      KS8851-16MLL is capable of switching bus endianness by a hardware strap,
      EESK pin. If this strap is incorrect, the IO accesses require such endian
      swapping as is being reverted by this patch. Such swapping also impacts
      the performance significantly.
      
      Hence, in addition to removing it, detect that the hardware is broken,
      report to user, and fail to bind with such hardware.
      
      Fixes: 58292104 ("net: ks8851-ml: Fix 16-bit IO operation")
      Fixes: edacb098 ("net: ks8851-ml: Fix 16-bit data access")
      Signed-off-by: default avatarMarek Vasut <marex@denx.de>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Lukas Wunner <lukas@wunner.de>
      Cc: Petr Stetiar <ynezz@true.cz>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b1d5cd9
    • Greg Kroah-Hartman's avatar
      bpf: Explicitly memset the bpf_attr structure · ce7656ea
      Greg Kroah-Hartman authored
      commit 8096f229 upstream.
      
      For the bpf syscall, we are relying on the compiler to properly zero out
      the bpf_attr union that we copy userspace data into. Unfortunately that
      doesn't always work properly, padding and other oddities might not be
      correctly zeroed, and in some tests odd things have been found when the
      stack is pre-initialized to other values.
      
      Fix this by explicitly memsetting the structure to 0 before using it.
      Reported-by: default avatarMaciej Żenczykowski <maze@google.com>
      Reported-by: default avatarJohn Stultz <john.stultz@linaro.org>
      Reported-by: default avatarAlexander Potapenko <glider@google.com>
      Reported-by: default avatarAlistair Delva <adelva@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://android-review.googlesource.com/c/kernel/common/+/1235490
      Link: https://lore.kernel.org/bpf/20200320094813.GA421650@kroah.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce7656ea
    • Eric Biggers's avatar
      vt: vt_ioctl: fix use-after-free in vt_in_use() · c47de1c0
      Eric Biggers authored
      commit 7cf64b18 upstream.
      
      vt_in_use() dereferences console_driver->ttys[i] without proper locking.
      This is broken because the tty can be closed and freed concurrently.
      
      We could fix this by using 'READ_ONCE(console_driver->ttys[i]) != NULL'
      and skipping the check of tty_struct::count.  But, looking at
      console_driver->ttys[i] isn't really appropriate anyway because even if
      it is NULL the tty can still be in the process of being closed.
      
      Instead, fix it by making vt_in_use() require console_lock() and check
      whether the vt is allocated and has port refcount > 1.  This works since
      following the patch "vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use
      virtual console" the port refcount is incremented while the vt is open.
      
      Reproducer (very unreliable, but it worked for me after a few minutes):
      
      	#include <fcntl.h>
      	#include <linux/vt.h>
      
      	int main()
      	{
      		int fd, nproc;
      		struct vt_stat state;
      		char ttyname[16];
      
      		fd = open("/dev/tty10", O_RDONLY);
      		for (nproc = 1; nproc < 8; nproc *= 2)
      			fork();
      		for (;;) {
      			sprintf(ttyname, "/dev/tty%d", rand() % 8);
      			close(open(ttyname, O_RDONLY));
      			ioctl(fd, VT_GETSTATE, &state);
      		}
      	}
      
      KASAN report:
      
      	BUG: KASAN: use-after-free in vt_in_use drivers/tty/vt/vt_ioctl.c:48 [inline]
      	BUG: KASAN: use-after-free in vt_ioctl+0x1ad3/0x1d70 drivers/tty/vt/vt_ioctl.c:657
      	Read of size 4 at addr ffff888065722468 by task syz-vt2/132
      
      	CPU: 0 PID: 132 Comm: syz-vt2 Not tainted 5.6.0-rc5-00130-g089b6d36 #13
      	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20191223_100556-anatol 04/01/2014
      	Call Trace:
      	 [...]
      	 vt_in_use drivers/tty/vt/vt_ioctl.c:48 [inline]
      	 vt_ioctl+0x1ad3/0x1d70 drivers/tty/vt/vt_ioctl.c:657
      	 tty_ioctl+0x9db/0x11b0 drivers/tty/tty_io.c:2660
      	 [...]
      
      	Allocated by task 136:
      	 [...]
      	 kzalloc include/linux/slab.h:669 [inline]
      	 alloc_tty_struct+0x96/0x8a0 drivers/tty/tty_io.c:2982
      	 tty_init_dev+0x23/0x350 drivers/tty/tty_io.c:1334
      	 tty_open_by_driver drivers/tty/tty_io.c:1987 [inline]
      	 tty_open+0x3ca/0xb30 drivers/tty/tty_io.c:2035
      	 [...]
      
      	Freed by task 41:
      	 [...]
      	 kfree+0xbf/0x200 mm/slab.c:3757
      	 free_tty_struct+0x8d/0xb0 drivers/tty/tty_io.c:177
      	 release_one_tty+0x22d/0x2f0 drivers/tty/tty_io.c:1468
      	 process_one_work+0x7f1/0x14b0 kernel/workqueue.c:2264
      	 worker_thread+0x8b/0xc80 kernel/workqueue.c:2410
      	 [...]
      
      Fixes: 4001d7b7 ("vt: push down the tty lock so we can see what is left to tackle")
      Cc: <stable@vger.kernel.org> # v3.4+
      Acked-by: default avatarJiri Slaby <jslaby@suse.cz>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Link: https://lore.kernel.org/r/20200322034305.210082-3-ebiggers@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c47de1c0
    • Peter Zijlstra's avatar
      locking/atomic, kref: Add kref_read() · ea9df3c8
      Peter Zijlstra authored
      commit 2c935bc5 upstream.
      
      Since we need to change the implementation, stop exposing internals.
      
      Provide kref_read() to read the current reference count; typically
      used for debug messages.
      
      Kills two anti-patterns:
      
      	atomic_read(&kref->refcount)
      	kref->refcount.counter
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      [only add kref_read() to kref.h for stable backports - gregkh]
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ea9df3c8
    • Eric Biggers's avatar
      vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console · 6bc9bf78
      Eric Biggers authored
      commit ca4463bf upstream.
      
      The VT_DISALLOCATE ioctl can free a virtual console while tty_release()
      is still running, causing a use-after-free in con_shutdown().  This
      occurs because VT_DISALLOCATE considers a virtual console's
      'struct vc_data' to be unused as soon as the corresponding tty's
      refcount hits 0.  But actually it may be still being closed.
      
      Fix this by making vc_data be reference-counted via the embedded
      'struct tty_port'.  A newly allocated virtual console has refcount 1.
      Opening it for the first time increments the refcount to 2.  Closing it
      for the last time decrements the refcount (in tty_operations::cleanup()
      so that it happens late enough), as does VT_DISALLOCATE.
      
      Reproducer:
      	#include <fcntl.h>
      	#include <linux/vt.h>
      	#include <sys/ioctl.h>
      	#include <unistd.h>
      
      	int main()
      	{
      		if (fork()) {
      			for (;;)
      				close(open("/dev/tty5", O_RDWR));
      		} else {
      			int fd = open("/dev/tty10", O_RDWR);
      
      			for (;;)
      				ioctl(fd, VT_DISALLOCATE, 5);
      		}
      	}
      
      KASAN report:
      	BUG: KASAN: use-after-free in con_shutdown+0x76/0x80 drivers/tty/vt/vt.c:3278
      	Write of size 8 at addr ffff88806a4ec108 by task syz_vt/129
      
      	CPU: 0 PID: 129 Comm: syz_vt Not tainted 5.6.0-rc2 #11
      	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20191223_100556-anatol 04/01/2014
      	Call Trace:
      	 [...]
      	 con_shutdown+0x76/0x80 drivers/tty/vt/vt.c:3278
      	 release_tty+0xa8/0x410 drivers/tty/tty_io.c:1514
      	 tty_release_struct+0x34/0x50 drivers/tty/tty_io.c:1629
      	 tty_release+0x984/0xed0 drivers/tty/tty_io.c:1789
      	 [...]
      
      	Allocated by task 129:
      	 [...]
      	 kzalloc include/linux/slab.h:669 [inline]
      	 vc_allocate drivers/tty/vt/vt.c:1085 [inline]
      	 vc_allocate+0x1ac/0x680 drivers/tty/vt/vt.c:1066
      	 con_install+0x4d/0x3f0 drivers/tty/vt/vt.c:3229
      	 tty_driver_install_tty drivers/tty/tty_io.c:1228 [inline]
      	 tty_init_dev+0x94/0x350 drivers/tty/tty_io.c:1341
      	 tty_open_by_driver drivers/tty/tty_io.c:1987 [inline]
      	 tty_open+0x3ca/0xb30 drivers/tty/tty_io.c:2035
      	 [...]
      
      	Freed by task 130:
      	 [...]
      	 kfree+0xbf/0x1e0 mm/slab.c:3757
      	 vt_disallocate drivers/tty/vt/vt_ioctl.c:300 [inline]
      	 vt_ioctl+0x16dc/0x1e30 drivers/tty/vt/vt_ioctl.c:818
      	 tty_ioctl+0x9db/0x11b0 drivers/tty/tty_io.c:2660
      	 [...]
      
      Fixes: 4001d7b7 ("vt: push down the tty lock so we can see what is left to tackle")
      Cc: <stable@vger.kernel.org> # v3.4+
      Reported-by: syzbot+522643ab5729b0421998@syzkaller.appspotmail.com
      Acked-by: default avatarJiri Slaby <jslaby@suse.cz>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Link: https://lore.kernel.org/r/20200322034305.210082-2-ebiggers@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6bc9bf78
    • Eric Biggers's avatar
      vt: vt_ioctl: remove unnecessary console allocation checks · 35d64801
      Eric Biggers authored
      commit 1aa6e058 upstream.
      
      The vc_cons_allocated() checks in vt_ioctl() and vt_compat_ioctl() are
      unnecessary because they can only be reached by calling ioctl() on an
      open tty, which implies the corresponding virtual console is allocated.
      
      And even if the virtual console *could* be freed concurrently, then
      these checks would be broken since they aren't done under console_lock,
      and the vc_data is dereferenced before them anyway.
      
      So, remove these unneeded checks to avoid confusion.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Link: https://lore.kernel.org/r/20200224080326.295046-1-ebiggers@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35d64801
    • Jiri Slaby's avatar
      vt: switch vt_dont_switch to bool · 2e1c84e1
      Jiri Slaby authored
      commit f400991b upstream.
      
      vt_dont_switch is pure boolean, no need for whole char.
      Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
      Link: https://lore.kernel.org/r/20200219073951.16151-6-jslaby@suse.czSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2e1c84e1