~kleber-souza/ubuntu/+source/linux/+git/xenial:xenial-update-to-4.4.218

Last commit made on 2020-04-20
Get this branch:
git clone -b xenial-update-to-4.4.218 https://git.launchpad.net/~kleber-souza/ubuntu/+source/linux/+git/xenial
Only Kleber Sacilotto de Souza can upload to this branch. If you are Kleber Sacilotto de Souza please log in for upload directions.

Branch merges

Branch information

Name:
xenial-update-to-4.4.218
Repository:
lp:~kleber-souza/ubuntu/+source/linux/+git/xenial

Recent commits

a2e7793... by Greg Kroah-Hartman <email address hidden>

Linux 4.4.218

BugLink: https://bugs.launchpad.net/bugs/1873852

Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

c9a5100... by disconnect3d <email address hidden>

perf map: Fix off by one in strncpy() size argument

BugLink: https://bugs.launchpad.net/bugs/1873852

commit db2c549407d4a76563c579e4768f7d6d32afefba 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: eca818369996 ("perf tools: Add automatic remapping of Android libraries")
Signed-off-by: disconnect3d <email address hidden>
Cc: Alexander Shishkin <email address hidden>
Cc: Changbin Du <email address hidden>
Cc: Jiri Olsa <email address hidden>
Cc: John Keeping <email address hidden>
Cc: Mark Rutland <email address hidden>
Cc: Michael Lentine <email address hidden>
Cc: Namhyung Kim <email address hidden>
Cc: Peter Zijlstra <email address hidden>
Cc: Song Liu <email address hidden>
Cc: Stephane Eranian <email address hidden>
Link: http://<email address hidden>
Signed-off-by: Arnaldo Carvalho de Melo <email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

c8900f2... by Marek Vasut <email address hidden>

net: ks8851-ml: Fix IO operations, again

BugLink: https://bugs.launchpad.net/bugs/1873852

commit 8262e6f9b1034ede34548a04dec4c302d92c9497 upstream.

This patch reverts 58292104832f ("net: ks8851-ml: Fix 16-bit IO operation")
and edacb098ea9c ("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: 58292104832f ("net: ks8851-ml: Fix 16-bit IO operation")
Fixes: edacb098ea9c ("net: ks8851-ml: Fix 16-bit data access")
Signed-off-by: Marek Vasut <email address hidden>
Cc: David S. Miller <email address hidden>
Cc: Lukas Wunner <email address hidden>
Cc: Petr Stetiar <email address hidden>
Cc: YueHaibing <email address hidden>
Signed-off-by: David S. Miller <email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

5ce406d... by Greg Kroah-Hartman <email address hidden>

bpf: Explicitly memset the bpf_attr structure

BugLink: https://bugs.launchpad.net/bugs/1873852

commit 8096f229421f7b22433775e928d506f0342e5907 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: Maciej Żenczykowski <email address hidden>
Reported-by: John Stultz <email address hidden>
Reported-by: Alexander Potapenko <email address hidden>
Reported-by: Alistair Delva <email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Daniel Borkmann <email address hidden>
Acked-by: Yonghong Song <email address hidden>
Link: https://android-review.googlesource.com/c/kernel/common/+/1235490
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

f2b9a9f... by Eric Biggers <email address hidden>

vt: vt_ioctl: fix use-after-free in vt_in_use()

BugLink: https://bugs.launchpad.net/bugs/1873852

commit 7cf64b18b0b96e751178b8d0505d8466ff5a448f 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-g089b6d3654916 #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: 4001d7b7fc27 ("vt: push down the tty lock so we can see what is left to tackle")
Cc: <email address hidden> # v3.4+
Acked-by: Jiri Slaby <email address hidden>
Signed-off-by: Eric Biggers <email address hidden>
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

e981db6... by Peter Zijlstra <email address hidden>

locking/atomic, kref: Add kref_read()

BugLink: https://bugs.launchpad.net/bugs/1873852

commit 2c935bc57221cc2edc787c72ea0e2d30cdcd3d5e 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: Peter Zijlstra (Intel) <email address hidden>
Cc: Andrew Morton <email address hidden>
Cc: Greg Kroah-Hartman <email address hidden>
Cc: Linus Torvalds <email address hidden>
Cc: Paul E. McKenney <email address hidden>
Cc: Peter Zijlstra <email address hidden>
Cc: Thomas Gleixner <email address hidden>
Cc: <email address hidden>
Signed-off-by: Ingo Molnar <email address hidden>
[only add kref_read() to kref.h for stable backports - gregkh]
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

9bb9a90... by Eric Biggers <email address hidden>

vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console

BugLink: https://bugs.launchpad.net/bugs/1873852

commit ca4463bf8438b403596edd0ec961ca0d4fbe0220 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: 4001d7b7fc27 ("vt: push down the tty lock so we can see what is left to tackle")
Cc: <email address hidden> # v3.4+
Reported-by: <email address hidden>
Acked-by: Jiri Slaby <email address hidden>
Signed-off-by: Eric Biggers <email address hidden>
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

36d019f... by Eric Biggers <email address hidden>

vt: vt_ioctl: remove unnecessary console allocation checks

BugLink: https://bugs.launchpad.net/bugs/1873852

commit 1aa6e058dd6cd04471b1f21298270014daf48ac9 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: Eric Biggers <email address hidden>
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

cd93260... by Jiri Slaby <email address hidden>

vt: switch vt_dont_switch to bool

BugLink: https://bugs.launchpad.net/bugs/1873852

commit f400991bf872debffb01c46da882dc97d7e3248e upstream.

vt_dont_switch is pure boolean, no need for whole char.

Signed-off-by: Jiri Slaby <email address hidden>
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>

b066df4... by Jiri Slaby <email address hidden>

vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines

BugLink: https://bugs.launchpad.net/bugs/1873852

commit e587e8f17433ddb26954f0edf5b2f95c42155ae9 upstream.

These two were macros. Switch them to static inlines, so that it's more
understandable what they are doing.

Signed-off-by: Jiri Slaby <email address hidden>
Link: https://<email address hidden>
Signed-off-by: Greg Kroah-Hartman <email address hidden>
Signed-off-by: Kleber Sacilotto de Souza <email address hidden>