profile/wearable/platform/kernel/linux-4.9-exynos9110.git
4 years agosoc: samsung: cal-if: fix not to calculate array size from null 18/220818/2
Seung-Woo Kim [Mon, 23 Dec 2019 08:23:37 +0000 (17:23 +0900)]
soc: samsung: cal-if: fix not to calculate array size from null

Calculating array size from null causes sizeof-pointer-div warning.
Fix not to calculate array size from null by adding pll macro
without NULL array.

Change-Id: I7002376523bd42cedaebc6443135c8410e5a1c46
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agovideo: fbdev: exynos: dpu9110: panel: s6e36w3x01: remove buffer overflow 17/220817/2
Seung-Woo Kim [Mon, 23 Dec 2019 08:29:02 +0000 (17:29 +0900)]
video: fbdev: exynos: dpu9110: panel: s6e36w3x01: remove buffer overflow

The memcpy to buffer has out of bounds for array. Remove the
buffer overflow for by adding additional array length.

Change-Id: I0aa5974fd39a6a7f705740ce1dcbf6ce15c2e935
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoAsoC: speedy: fix sizeof-pointer-memaccess for strncpy() 16/220816/2
Seung-Woo Kim [Mon, 23 Dec 2019 07:20:00 +0000 (16:20 +0900)]
AsoC: speedy: fix sizeof-pointer-memaccess for strncpy()

The strncpy() is done with sizeof() for source. Fix warning from
sizeof-pointer-memaccess by replacing sizeof() for destination.

Change-Id: I2e4bbdda84e90391d8767358ebebb12bdc10154e
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agonet: bcmdhd: Fix string concatenate with strncat() 15/220815/2
Seung-Woo Kim [Mon, 23 Dec 2019 07:58:25 +0000 (16:58 +0900)]
net: bcmdhd: Fix string concatenate with strncat()

There is stringop-overflow warning to use strncat and bound check
for buffer size for the string is already done. Fix string
concatenate with strncat() by replacing with strcat().

Change-Id: I8c009e4d76f5044601bacd596d4ca872bb69fd1f
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoarm64: tizen_tw3_defconfig: Enable CONFIG_CRYPTO_CCM 41/221041/2
Anupam Roy [Thu, 26 Dec 2019 11:26:02 +0000 (16:56 +0530)]
arm64: tizen_tw3_defconfig: Enable CONFIG_CRYPTO_CCM

Enable CONFIG_CRYPTO_CCM config option for using
AEAD-AES_CCM encryption. AEAD socket with
AES_CCM cipher type is used by Bluetooth Mesh
functionality for encryption & decryption.

Change-Id: I8b940288c2763ebc3007d5a419329f392b41ad8b
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
4 years agoarm64: tizen_tw3_defconfig: sync USB_CONFIGFS related config options 56/221056/1
Seung-Woo Kim [Fri, 27 Dec 2019 00:59:16 +0000 (09:59 +0900)]
arm64: tizen_tw3_defconfig: sync USB_CONFIGFS related config options

After CONFIG_USB_CONFIGFS is enabled, defconfig was not fully
updated. Sync realted config options.

Change-Id: I96c99483933f0c84bd48b0f67110a469bf245ef7
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agocfg80211: Fix array-bounds warning in fragment copy 14/220814/1
Matthias Kaehlcke [Thu, 13 Apr 2017 17:05:04 +0000 (10:05 -0700)]
cfg80211: Fix array-bounds warning in fragment copy

commit aa1702dd162f420bf85ecef0c77686ef0dbc1496 upstream.

__ieee80211_amsdu_copy_frag intentionally initializes a pointer to
array[-1] to increment it later to valid values. clang rightfully
generates an array-bounds warning on the initialization statement.

Initialize the pointer to array[0] and change the algorithm from
increment before to increment after consume.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Cc: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 4bb797afd7ba for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ibb581c74dc67fcc867f7fa58d20cb1b225caa852

4 years agoip_tunnel: Fix name string concatenate in __ip_tunnel_create() 13/220813/1
Sultan Alsawaf [Wed, 6 Jun 2018 22:56:54 +0000 (15:56 -0700)]
ip_tunnel: Fix name string concatenate in __ip_tunnel_create()

commit 000ade8016400d93b4d7c89970d96b8c14773d45 upstream.

By passing a limit of 2 bytes to strncat, strncat is limited to writing
fewer bytes than what it's supposed to append to the name here.

Since the bounds are checked on the line above this, just remove the string
bounds checks entirely since they're unneeded.

Signed-off-by: Sultan Alsawaf <sultanxda@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 5569c10858be for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ida4f04d469c4d91f12faa5fe46bd443c43bfe333

4 years agotracing: Silence GCC 9 array bounds warning 12/220812/1
Miguel Ojeda [Thu, 23 May 2019 12:45:35 +0000 (14:45 +0200)]
tracing: Silence GCC 9 array bounds warning

commit 0c97bf863efce63d6ab7971dad811601e6171d2f upstream.

Starting with GCC 9, -Warray-bounds detects cases when memset is called
starting on a member of a struct but the size to be cleared ends up
writing over further members.

Such a call happens in the trace code to clear, at once, all members
after and including `seq` on struct trace_iterator:

    In function 'memset',
        inlined from 'ftrace_dump' at kernel/trace/trace.c:8914:3:
    ./include/linux/string.h:344:9: warning: '__builtin_memset' offset
    [8505, 8560] from the object at 'iter' is out of the bounds of
    referenced subobject 'seq' with type 'struct trace_seq' at offset
    4368 [-Warray-bounds]
      344 |  return __builtin_memset(p, c, size);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to avoid GCC complaining about it, we compute the address
ourselves by adding the offsetof distance instead of referring
directly to the member.

Since there are two places doing this clear (trace.c and trace_kdb.c),
take the chance to move the workaround into a single place in
the internal header.

Link: http://lkml.kernel.org/r/20190523124535.GA12931@gmail.com
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
[ Removed unnecessary parenthesis around "iter" ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 2e41539ee26f for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I82d986a1e1a6a447c2fd3b5c3af3145192e72748

4 years agogcc-9: silence 'address-of-packed-member' warning 11/220811/1
Linus Torvalds [Wed, 1 May 2019 18:05:41 +0000 (11:05 -0700)]
gcc-9: silence 'address-of-packed-member' warning

commit 6f303d60534c46aa1a239f29c321f95c83dda748 upstream.

We already did this for clang, but now gcc has that warning too.  Yes,
yes, the address may be unaligned.  And that's kind of the point.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 7601d81506ef for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Id774c5d5a37b7761a7792be0fedc7282f19d45f8

4 years agounifdef: use memcpy instead of strncpy 10/220810/1
Linus Torvalds [Fri, 30 Nov 2018 22:45:01 +0000 (14:45 -0800)]
unifdef: use memcpy instead of strncpy

commit 38c7b224ce22c25fed04007839edf974bd13439d upstream.

New versions of gcc reasonably warn about the odd pattern of

strncpy(p, q, strlen(q));

which really doesn't make sense: the strncpy() ends up being just a slow
and odd way to write memcpy() in this case.

There was a comment about _why_ the code used strncpy - to avoid the
terminating NUL byte, but memcpy does the same and avoids the warning.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 0d4a2de44713 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I3adb0d708af7d8a55216d6c81d1e691b8d30e8c1

4 years agoarm64, vdso: Define vdso_{start,end} as array 09/220809/1
Kees Cook [Fri, 5 Jul 2019 18:47:20 +0000 (20:47 +0200)]
arm64, vdso: Define vdso_{start,end} as array

Commit dbbb08f500d6146398b794fdc68a8e811366b451 upstream.

Adjust vdso_{start|end} to be char arrays to avoid compile-time analysis
that flags "too large" memcmp() calls with CONFIG_FORTIFY_SOURCE.

Cc: Jisheng Zhang <jszhang@marvell.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 830d3a71e1ce for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I32aa68e1365d0389f05ab456f82b3b72f10b60da

4 years agoKbuild: suppress packed-not-aligned warning for default setting only 08/220808/1
Xiongfeng Wang [Thu, 11 Jan 2018 09:22:29 +0000 (17:22 +0800)]
Kbuild: suppress packed-not-aligned warning for default setting only

commit 321cb0308a9e76841394b4bbab6a1107cfedbae0 upstream.

gcc-8 reports many -Wpacked-not-aligned warnings. The below are some
examples.

./include/linux/ceph/msgr.h:67:1: warning: alignment 1 of 'struct
ceph_entity_addr' is less than 8 [-Wpacked-not-aligned]
 } __attribute__ ((packed));

./include/linux/ceph/msgr.h:67:1: warning: alignment 1 of 'struct
ceph_entity_addr' is less than 8 [-Wpacked-not-aligned]
 } __attribute__ ((packed));

./include/linux/ceph/msgr.h:67:1: warning: alignment 1 of 'struct
ceph_entity_addr' is less than 8 [-Wpacked-not-aligned]
 } __attribute__ ((packed));

This patch suppresses this kind of warnings for default setting.

Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit dfb64b8c3d26 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I9fe83e410fbf2ddd0ce52842ed1f5c24efce260a

4 years agodisable stringop truncation warnings for now 07/220807/1
Stephen Rothwell [Thu, 30 Aug 2018 21:47:28 +0000 (07:47 +1000)]
disable stringop truncation warnings for now

commit 217c3e0196758662aa0429863b09d1c13da1c5d6 upstream.

They are too noisy

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 5e2669c978b2 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I57286951ce59491105cc89ec99277a180b3c7478

4 years agokconfig: Avoid format overflow warning from GCC 8.1 06/220806/1
Nathan Chancellor [Sat, 2 Jun 2018 16:02:09 +0000 (09:02 -0700)]
kconfig: Avoid format overflow warning from GCC 8.1

commit 2ae89c7a82ea9d81a19b4fc2df23bef4b112f24e upstream.

In file included from scripts/kconfig/zconf.tab.c:2485:
scripts/kconfig/confdata.c: In function ‘conf_write’:
scripts/kconfig/confdata.c:773:22: warning: ‘%s’ directive writing likely 7 or more bytes into a region of size between 1 and 4097 [-Wformat-overflow=]
  sprintf(newname, "%s%s", dirname, basename);
                      ^~
scripts/kconfig/confdata.c:773:19: note: assuming directive output of 7 bytes
  sprintf(newname, "%s%s", dirname, basename);
                   ^~~~~~
scripts/kconfig/confdata.c:773:2: note: ‘sprintf’ output 1 or more bytes (assuming 4104) into a destination of size 4097
  sprintf(newname, "%s%s", dirname, basename);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scripts/kconfig/confdata.c:776:23: warning: ‘.tmpconfig.’ directive writing 11 bytes into a region of size between 1 and 4097 [-Wformat-overflow=]
   sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
                       ^~~~~~~~~~~
scripts/kconfig/confdata.c:776:3: note: ‘sprintf’ output between 13 and 4119 bytes into a destination of size 4097
   sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Increase the size of tmpname and newname to make GCC happy.

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit 1ec1dfba0835 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I7ebafa60f7703732795fe226b1c1eb8c39a27c28

4 years agoexec: avoid gcc-8 warning for get_task_comm 05/220805/1
Arnd Bergmann [Thu, 14 Dec 2017 23:32:41 +0000 (15:32 -0800)]
exec: avoid gcc-8 warning for get_task_comm

commit 3756f6401c302617c5e091081ca4d26ab604bec5 upstream.

gcc-8 warns about using strncpy() with the source size as the limit:

  fs/exec.c:1223:32: error: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]

This is indeed slightly suspicious, as it protects us from source
arguments without NUL-termination, but does not guarantee that the
destination is terminated.

This keeps the strncpy() to ensure we have properly padded target
buffer, but ensures that we use the correct length, by passing the
actual length of the destination buffer as well as adding a build-time
check to ensure it is exactly TASK_COMM_LEN.

There are only 23 callsites which I all reviewed to ensure this is
currently the case.  We could get away with doing only the check or
passing the right length, but it doesn't hurt to do both.

Link: http://lkml.kernel.org/r/20171205151724.1764896-1-arnd@arndb.de
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Kees Cook <keescook@chromium.org>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Aleksa Sarai <asarai@suse.de>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit b9dd13488acb for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I1d5a998bca751044ef2ac01e569ee500047beb0f

4 years agoturn off -Wattribute-alias 04/220804/1
Arnd Bergmann [Thu, 26 Jul 2018 08:13:22 +0000 (10:13 +0200)]
turn off -Wattribute-alias

Starting with gcc-8.1, we get a warning about all system call definitions,
which use an alias between functions with incompatible prototypes, e.g.:

In file included from ../mm/process_vm_access.c:19:
../include/linux/syscalls.h:211:18: warning: 'sys_process_vm_readv' alias between functions of incompatible types 'long int(pid_t,  const struct iovec *, long unsigned int,  const struct iovec *, long unsigned int,  long unsigned int)' {aka 'long int(int,  const struct iovec *, long unsigned int,  const struct iovec *, long unsigned int,  long unsigned int)'} and 'long int(long int,  long int,  long int,  long int,  long int,  long int)' [-Wattribute-alias]
  asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
                  ^~~
../include/linux/syscalls.h:207:2: note: in expansion of macro '__SYSCALL_DEFINEx'
  __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
  ^~~~~~~~~~~~~~~~~
../include/linux/syscalls.h:201:36: note: in expansion of macro 'SYSCALL_DEFINEx'
 #define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
                                    ^~~~~~~~~~~~~~~
../mm/process_vm_access.c:300:1: note: in expansion of macro 'SYSCALL_DEFINE6'
 SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec,
 ^~~~~~~~~~~~~~~
../include/linux/syscalls.h:215:18: note: aliased declaration here
  asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
                  ^~~
../include/linux/syscalls.h:207:2: note: in expansion of macro '__SYSCALL_DEFINEx'
  __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
  ^~~~~~~~~~~~~~~~~
../include/linux/syscalls.h:201:36: note: in expansion of macro 'SYSCALL_DEFINEx'
 #define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
                                    ^~~~~~~~~~~~~~~
../mm/process_vm_access.c:300:1: note: in expansion of macro 'SYSCALL_DEFINE6'
 SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec,

This is really noisy and does not indicate a real problem. In the latest
mainline kernel, this was addressed by commit bee20031772a ("disable
-Wattribute-alias warning for SYSCALL_DEFINEx()"), which seems too invasive
to backport.

This takes a much simpler approach and just disables the warning across the
kernel.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-4.9.y commit b1a1d9bdb1b5 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I930f1ed6c9350d8131e363f2feb0a73bee68007b

4 years agodrm/tgm: tdm_pp: msc: check and adjust src/dest size parameter 50/220750/1 accepted/tizen/unified/20191223.060227 submit/tizen/20191223.042319
Seung-Woo Kim [Mon, 23 Dec 2019 01:21:38 +0000 (10:21 +0900)]
drm/tgm: tdm_pp: msc: check and adjust src/dest size parameter

In msc hw, for both src and dest, image x plus image w should be
equal or less than buffer size vsize and image y plus image shou.d
be equal or less than buffer size hsize. Otherwise, hw tries to
access out of buffer boundary and it causes msc sysmmu page fault.
Fix to check and to adjust src/dest size parameter as the hw
constraint.

Change-Id: Ie6e9d431955e0c369164f2b1f46cf9f17e0b1d8b
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agousb: gadget: f_fs: Give chance to retry malloc for large size buffer 05/220605/3
Dongwoo Lee [Fri, 26 Oct 2018 01:41:41 +0000 (10:41 +0900)]
usb: gadget: f_fs: Give chance to retry malloc for large size buffer

The f_fs daemons usually use large size buffer for increasing transfer
performance, but it can cause memory allocation failure in case of
that buddy space is fragmented. Since this, instead of just returning
error in this case, give the chance to retry to allocate memory with
a half length in order to prevent daemon crash due to failure of
buffer allocation.

Change-Id: I2171932b8cb565102d63eb82c114987b85d26ed9
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
4 years agoBluetooth: Enables filter_policy and adv_type set by user 15/220215/5
Amit Purwar [Mon, 16 Dec 2019 05:58:59 +0000 (11:28 +0530)]
Bluetooth: Enables filter_policy and adv_type set by user

This patch enables the filter_policy and adv_type in advertisement
set by user on MGMT interface using set_advertising_params API.
Currently filter policy and adv_type does not get applied on slot 0
during ADV enable.

Change-Id: I18b2d5bb1db334f2f008b619503582c5eed29f08
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
4 years agoarm64: tizen_tw3_defconfig: Use configfs instead of legacy usb gadget 16/218616/1 accepted/tizen/unified/20191127.020253 submit/tizen/20191126.032220
Dongwoo Lee [Fri, 22 Nov 2019 06:16:34 +0000 (15:16 +0900)]
arm64: tizen_tw3_defconfig: Use configfs instead of legacy usb gadget

This patch replaces legacy gadget driver with configfs with CDC ACM,
rndis, functionfs support.

Change-Id: I8d96a3e95273ab830b1adf045b641024ed4a50a1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
4 years agousb: gadget: configfs: fix concurrent issue between composite APIs 03/218603/1
Peter Chen [Mon, 26 Aug 2019 19:10:55 +0000 (15:10 -0400)]
usb: gadget: configfs: fix concurrent issue between composite APIs

[ Upstream commit 1a1c851bbd706ea9f3a9756c2d3db28523506d3b ]

We meet several NULL pointer issues if configfs_composite_unbind
and composite_setup (or composite_disconnect) are running together.
These issues occur when do the function switch stress test, the
configfs_compsoite_unbind is called from user mode by
echo "" to /sys/../UDC entry, and meanwhile, the setup interrupt
or disconnect interrupt occurs by hardware. The composite_setup
will get the cdev from get_gadget_data, but configfs_composite_unbind
will set gadget data as NULL, so the NULL pointer issue occurs.
This concurrent is hard to reproduce by native kernel, but can be
reproduced by android kernel.

In this commit, we introduce one spinlock belongs to structure
gadget_info since we can't use the same spinlock in usb_composite_dev
due to exclusive running together between composite_setup and
configfs_composite_unbind. And one bit flag 'unbind' to indicate the
code is at unbind routine, this bit is needed due to we release the
lock at during configfs_composite_unbind sometimes, and composite_setup
may be run at that time.

Several oops:

oops 1:
android_work: sent uevent USB_STATE=CONNECTED
configfs-gadget gadget: super-speed config #1: b
android_work: sent uevent USB_STATE=CONFIGURED
init: Received control message 'start' for 'adbd' from pid: 3515 (system_server)
Unable to handle kernel NULL pointer dereference at virtual address 0000002a
init: Received control message 'stop' for 'adbd' from pid: 3375 (/vendor/bin/hw/android.hardware.usb@1.1-servic)
Mem abort info:
  Exception class = DABT (current EL), IL = 32 bits
  SET = 0, FnV = 0
  EA = 0, S1PTW = 0
Data abort info:
  ISV = 0, ISS = 0x00000004
  CM = 0, WnR = 0
user pgtable: 4k pages, 48-bit VAs, pgd = ffff8008f1b7f000
[000000000000002a] *pgd=0000000000000000
Internal error: Oops: 96000004 [#1] PREEMPT SMP
Modules linked in:
CPU: 4 PID: 2457 Comm: irq/125-5b11000 Not tainted 4.14.98-07846-g0b40a9b-dirty #16
Hardware name: Freescale i.MX8QM MEK (DT)
task: ffff8008f2a98000 task.stack: ffff00000b7b8000
PC is at composite_setup+0x44/0x1508
LR is at android_setup+0xb8/0x13c
pc : [<ffff0000089ffb3c>] lr : [<ffff000008a032fc>] pstate: 800001c5
sp : ffff00000b7bbb80
x29: ffff00000b7bbb80 x28: ffff8008f2a3c010
x27: 0000000000000001 x26: 0000000000000000                                                          [1232/1897]
audit: audit_lost=25791 audit_rate_limit=5 audit_backlog_limit=64
x25: 00000000ffffffa1 x24: ffff8008f2a3c010
audit: rate limit exceeded
x23: 0000000000000409 x22: ffff000009c8e000
x21: ffff8008f7a8b428 x20: ffff00000afae000
x19: ffff0000089ff000 x18: 0000000000000000
x17: 0000000000000000 x16: ffff0000082b7c9c
x15: 0000000000000000 x14: f1866f5b952aca46
x13: e35502e30d44349c x12: 0000000000000008
x11: 0000000000000008 x10: 0000000000000a30
x9 : ffff00000b7bbd00 x8 : ffff8008f2a98a90
x7 : ffff8008f27a9c90 x6 : 0000000000000001
x5 : 0000000000000000 x4 : 0000000000000001
x3 : 0000000000000000 x2 : 0000000000000006
x1 : ffff0000089ff8d0 x0 : 732a010310b9ed00

X7: 0xffff8008f27a9c10:
9c10  00000002 00000000 00000001 00000000 13110000 ffff0000 00000002 00208040
9c30  00000000 00000000 00000000 00000000 00000000 00000005 00000029 00000000
9c50  00051778 00000001 f27a8e00 ffff8008 00000005 00000000 00000078 00000078
9c70  00000078 00000000 09031d48 ffff0000 00100000 00000000 00400000 00000000
9c90  00000001 00000000 00000000 00000000 00000000 00000000 ffefb1a0 ffff8008
9cb0  f27a9ca8 ffff8008 00000000 00000000 b9d88037 00000173 1618a3eb 00000001
9cd0  870a792a 0000002e 16188fe6 00000001 0000242b 00000000 00000000 00000000
using random self ethernet address
9cf0  019a4646 00000000 000547f3 00000000 ecfd6c33 00000002 00000000
using random host ethernet address
 00000000

X8: 0xffff8008f2a98a10:
8a10  00000000 00000000 f7788d00 ffff8008 00000001 00000000 00000000 00000000
8a30  eb218000 ffff8008 f2a98000 ffff8008 f2a98000 ffff8008 09885000 ffff0000
8a50  f34df480 ffff8008 00000000 00000000 f2a98648 ffff8008 09c8e000 ffff0000
8a70  fff2c800 ffff8008 09031d48 ffff0000 0b7bbd00 ffff0000 0b7bbd00 ffff0000
8a90  080861bc ffff0000 00000000 00000000 00000000 00000000 00000000 00000000
8ab0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8ad0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8af0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

X21: 0xffff8008f7a8b3a8:
b3a8  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
b3c8  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
b3e8  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
b408  00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000000
b428  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
b448  0053004d 00540046 00300031 00010030 eb07b520 ffff8008 20011201 00000003
b468  e418d109 0104404e 00010302 00000000 eb07b558 ffff8008 eb07b558 ffff8008
b488  f7a8b488 ffff8008 f7a8b488 ffff8008 f7a8b300 ffff8008 00000000 00000000

X24: 0xffff8008f2a3bf90:
bf90  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bfb0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bfd0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bff0  00000000 00000000 00000000 00000000 f76c8010 ffff8008 f76c8010 ffff8008
c010  00000000 00000000 f2a3c018 ffff8008 f2a3c018 ffff8008 08a067dc ffff0000
c030  f2a5a000 ffff8008 091c3650 ffff0000 f716fd18 ffff8008 f716fe30 ffff8008
c050  f2ce4a30 ffff8008 00000000 00000005 00000000 00000000 095d1568 ffff0000
c070  f76c8010 ffff8008 f2ce4b00 ffff8008 095cac68 ffff0000 f2a5a028 ffff8008

X28: 0xffff8008f2a3bf90:
bf90  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bfb0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bfd0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
bff0  00000000 00000000 00000000 00000000 f76c8010 ffff8008 f76c8010 ffff8008
c010  00000000 00000000 f2a3c018 ffff8008 f2a3c018 ffff8008 08a067dc ffff0000
c030  f2a5a000 ffff8008 091c3650 ffff0000 f716fd18 ffff8008 f716fe30 ffff8008
c050  f2ce4a30 ffff8008 00000000 00000005 00000000 00000000 095d1568 ffff0000
c070  f76c8010 ffff8008 f2ce4b00 ffff8008 095cac68 ffff0000 f2a5a028 ffff8008

Process irq/125-5b11000 (pid: 2457, stack limit = 0xffff00000b7b8000)
Call trace:
Exception stack(0xffff00000b7bba40 to 0xffff00000b7bbb80)
ba40: 732a010310b9ed00 ffff0000089ff8d0 0000000000000006 0000000000000000
ba60: 0000000000000001 0000000000000000 0000000000000001 ffff8008f27a9c90
ba80: ffff8008f2a98a90 ffff00000b7bbd00 0000000000000a30 0000000000000008
baa0: 0000000000000008 e35502e30d44349c f1866f5b952aca46 0000000000000000
bac0: ffff0000082b7c9c 0000000000000000 0000000000000000 ffff0000089ff000
bae0: ffff00000afae000 ffff8008f7a8b428 ffff000009c8e000 0000000000000409
bb00: ffff8008f2a3c010 00000000ffffffa1 0000000000000000 0000000000000001
bb20: ffff8008f2a3c010 ffff00000b7bbb80 ffff000008a032fc ffff00000b7bbb80
bb40: ffff0000089ffb3c 00000000800001c5 ffff00000b7bbb80 732a010310b9ed00
bb60: ffffffffffffffff ffff0000080f777c ffff00000b7bbb80 ffff0000089ffb3c
[<ffff0000089ffb3c>] composite_setup+0x44/0x1508
[<ffff000008a032fc>] android_setup+0xb8/0x13c
[<ffff0000089bd9a8>] cdns3_ep0_delegate_req+0x44/0x70
[<ffff0000089bdff4>] cdns3_check_ep0_interrupt_proceed+0x33c/0x654
[<ffff0000089bca44>] cdns3_device_thread_irq_handler+0x4b0/0x4bc
[<ffff0000089b77b4>] cdns3_thread_irq+0x48/0x68
[<ffff000008145bf0>] irq_thread_fn+0x28/0x88
[<ffff000008145e38>] irq_thread+0x13c/0x228
[<ffff0000080fed70>] kthread+0x104/0x130
[<ffff000008085064>] ret_from_fork+0x10/0x18

oops2:
composite_disconnect: Calling disconnect on a Gadget that is                      not connected
android_work: did not send uevent (0 0           (null))
init: Received control message 'stop' for 'adbd' from pid: 3359 (/vendor/bin/hw/android.hardware.usb@1.1-service.imx)
init: Sending signal 9 to service 'adbd' (pid 22343) process group...
------------[ cut here ]------------
audit: audit_lost=180038 audit_rate_limit=5 audit_backlog_limit=64
audit: rate limit exceeded
WARNING: CPU: 0 PID: 3468 at kernel_imx/drivers/usb/gadget/composite.c:2009 composite_disconnect+0x80/0x88
Modules linked in:
CPU: 0 PID: 3468 Comm: HWC-UEvent-Thre Not tainted 4.14.98-07846-g0b40a9b-dirty #16
Hardware name: Freescale i.MX8QM MEK (DT)
task: ffff8008f2349c00 task.stack: ffff00000b0a8000
PC is at composite_disconnect+0x80/0x88
LR is at composite_disconnect+0x80/0x88
pc : [<ffff0000089ff9b0>] lr : [<ffff0000089ff9b0>] pstate: 600001c5
sp : ffff000008003dd0
x29: ffff000008003dd0 x28: ffff8008f2349c00
x27: ffff000009885018 x26: ffff000008004000
Timeout for IPC response!
x25: ffff000009885018 x24: ffff000009c8e280
x23: ffff8008f2d98010 x22: 00000000000001c0
x21: ffff8008f2d98394 x20: ffff8008f2d98010
x19: 0000000000000000 x18: 0000e3956f4f075a
fxos8700 4-001e: i2c block read acc failed
x17: 0000e395735727e8 x16: ffff00000829f4d4
x15: ffffffffffffffff x14: 7463656e6e6f6320
x13: 746f6e2009090920 x12: 7369207461687420
x11: 7465676461472061 x10: 206e6f207463656e
x9 : 6e6f637369642067 x8 : ffff000009c8e280
x7 : ffff0000086ca6cc x6 : ffff000009f15e78
x5 : 0000000000000000 x4 : 0000000000000000
x3 : ffffffffffffffff x2 : c3f28b86000c3900
x1 : c3f28b86000c3900 x0 : 000000000000004e

X20: 0xffff8008f2d97f90:
7f90  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
7fb0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
libprocessgroup: Failed to kill process cgroup uid 0 pid 22343 in 215ms, 1 processes remain
7fd0
Timeout for IPC response!
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
using random self ethernet address
7ff0  00000000 00000000 00000000 00000000 f76c8010 ffff8008 f76c8010 ffff8008
8010  00000100 00000000 f2d98018 ffff8008 f2d98018 ffff8008 08a067dc
using random host ethernet address
 ffff0000
8030  f206d800 ffff8008 091c3650 ffff0000 f7957b18 ffff8008 f7957730 ffff8008
8050  f716a630 ffff8008 00000000 00000005 00000000 00000000 095d1568 ffff0000
8070  f76c8010 ffff8008 f716a800 ffff8008 095cac68 ffff0000 f206d828 ffff8008

X21: 0xffff8008f2d98314:
8314  ffff8008 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8334  00000000 00000000 00000000 00000000 00000000 08a04cf4 ffff0000 00000000
8354  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8374  00000000 00000000 00000000 00001001 00000000 00000000 00000000 00000000
8394  e4bbe4bb 0f230000 ffff0000 0afae000 ffff0000 ae001000 00000000 f206d400
Timeout for IPC response!
83b4  ffff8008 00000000 00000000 f7957b18 ffff8008 f7957718 ffff8008 f7957018
83d4  ffff8008 f7957118 ffff8008 f7957618 ffff8008 f7957818 ffff8008 f7957918
83f4  ffff8008 f7957d18 ffff8008 00000000 00000000 00000000 00000000 00000000

X23: 0xffff8008f2d97f90:
7f90  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
7fb0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
7fd0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
7ff0  00000000 00000000 00000000 00000000 f76c8010 ffff8008 f76c8010 ffff8008
8010  00000100 00000000 f2d98018 ffff8008 f2d98018 ffff8008 08a067dc ffff0000
8030  f206d800 ffff8008 091c3650 ffff0000 f7957b18 ffff8008 f7957730 ffff8008
8050  f716a630 ffff8008 00000000 00000005 00000000 00000000 095d1568 ffff0000
8070  f76c8010 ffff8008 f716a800 ffff8008 095cac68 ffff0000 f206d828 ffff8008

X28: 0xffff8008f2349b80:
9b80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9ba0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9bc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9be0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9c00  00000022 00000000 ffffffff ffffffff 00010001 00000000 00000000 00000000
9c20  0b0a8000 ffff0000 00000002 00404040 00000000 00000000 00000000 00000000
9c40  00000001 00000000 00000001 00000000 001ebd44 00000001 f390b800 ffff8008
9c60  00000000 00000001 00000070 00000070 00000070 00000000 09031d48 ffff0000

Call trace:
Exception stack(0xffff000008003c90 to 0xffff000008003dd0)
3c80:                                   000000000000004e c3f28b86000c3900
3ca0: c3f28b86000c3900 ffffffffffffffff 0000000000000000 0000000000000000
3cc0: ffff000009f15e78 ffff0000086ca6cc ffff000009c8e280 6e6f637369642067
3ce0: 206e6f207463656e 7465676461472061 7369207461687420 746f6e2009090920
3d00: 7463656e6e6f6320 ffffffffffffffff ffff00000829f4d4 0000e395735727e8
3d20: 0000e3956f4f075a 0000000000000000 ffff8008f2d98010 ffff8008f2d98394
3d40: 00000000000001c0 ffff8008f2d98010 ffff000009c8e280 ffff000009885018
3d60: ffff000008004000 ffff000009885018 ffff8008f2349c00 ffff000008003dd0
3d80: ffff0000089ff9b0 ffff000008003dd0 ffff0000089ff9b0 00000000600001c5
3da0: ffff8008f33f2cd8 0000000000000000 0000ffffffffffff 0000000000000000
init: Received control message 'start' for 'adbd' from pid: 3359 (/vendor/bin/hw/android.hardware.usb@1.1-service.imx)
3dc0: ffff000008003dd0 ffff0000089ff9b0
[<ffff0000089ff9b0>] composite_disconnect+0x80/0x88
[<ffff000008a044d4>] android_disconnect+0x3c/0x68
[<ffff0000089ba9f8>] cdns3_device_irq_handler+0xfc/0x2c8
[<ffff0000089b84c0>] cdns3_irq+0x44/0x94
[<ffff00000814494c>] __handle_irq_event_percpu+0x60/0x24c
[<ffff000008144c0c>] handle_irq_event+0x58/0xc0
[<ffff00000814873c>] handle_fasteoi_irq+0x98/0x180
[<ffff000008143a10>] generic_handle_irq+0x24/0x38
[<ffff000008144170>] __handle_domain_irq+0x60/0xac
[<ffff0000080819c4>] gic_handle_irq+0xd4/0x17c

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 59682e70c980 and resolve conflicts to stablize configfs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I891e07b46cb1783e5f1c7a1c5a6198bb62611b20

4 years agousb: gadget: configs: plug memory leak 02/218602/1
John Keeping [Tue, 28 Feb 2017 10:55:30 +0000 (10:55 +0000)]
usb: gadget: configs: plug memory leak

[ Upstream commit 38355b2a44776c25b0f2ad466e8c51bb805b3032 ]

When binding a gadget to a device, "name" is stored in gi->udc_name, but
this does not happen when unregistering and the string is leaked.

Signed-off-by: John Keeping <john@metanate.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 59682e70c980 to stablize configfs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: Ieb2bcfeed245a0b993ac6c4992af8fe27fc89d48

4 years agousb: gadget: Zero ffs_io_data 00/218600/1
Andrzej Pietrasiewicz [Mon, 3 Jun 2019 17:05:28 +0000 (19:05 +0200)]
usb: gadget: Zero ffs_io_data

[ Upstream commit 508595515f4bcfe36246e4a565cf280937aeaade ]

In some cases the "Allocate & copy" block in ffs_epfile_io() is not
executed. Consequently, in such a case ffs_alloc_buffer() is never called
and struct ffs_io_data is not initialized properly. This in turn leads to
problems when ffs_free_buffer() is called at the end of ffs_epfile_io().

This patch uses kzalloc() instead of kmalloc() in the aio case and memset()
in non-aio case to properly initialize struct ffs_io_data.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit d585589e5f9b to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I33ef7d5123301beb94b9d8530664d861464f4bb1

4 years agousb: f_fs: Avoid crash due to out-of-scope stack ptr access 99/218599/1
John Stultz [Tue, 5 Feb 2019 18:24:40 +0000 (10:24 -0800)]
usb: f_fs: Avoid crash due to out-of-scope stack ptr access

[ Upstream commit 54f64d5c983f939901dacc8cfc0983727c5c742e ]

Since the 5.0 merge window opened, I've been seeing frequent
crashes on suspend and reboot with the trace:

[   36.911170] Unable to handle kernel paging request at virtual address ffffff801153d660
[   36.912769] Unable to handle kernel paging request at virtual address ffffff800004b564
...
[   36.950666] Call trace:
[   36.950670]  queued_spin_lock_slowpath+0x1cc/0x2c8
[   36.950681]  _raw_spin_lock_irqsave+0x64/0x78
[   36.950692]  complete+0x28/0x70
[   36.950703]  ffs_epfile_io_complete+0x3c/0x50
[   36.950713]  usb_gadget_giveback_request+0x34/0x108
[   36.950721]  dwc3_gadget_giveback+0x50/0x68
[   36.950723]  dwc3_thread_interrupt+0x358/0x1488
[   36.950731]  irq_thread_fn+0x30/0x88
[   36.950734]  irq_thread+0x114/0x1b0
[   36.950739]  kthread+0x104/0x130
[   36.950747]  ret_from_fork+0x10/0x1c

I isolated this down to in ffs_epfile_io():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/gadget/function/f_fs.c#n1065

Where the completion done is setup on the stack:
  DECLARE_COMPLETION_ONSTACK(done);

Then later we setup a request and queue it, and wait for it:
  if (unlikely(wait_for_completion_interruptible(&done))) {
    /*
    * To avoid race condition with ffs_epfile_io_complete,
    * dequeue the request first then check
    * status. usb_ep_dequeue API should guarantee no race
    * condition with req->complete callback.
    */
    usb_ep_dequeue(ep->ep, req);
    interrupted = ep->status < 0;
  }

The problem is, that we end up being interrupted, dequeue the
request, and exit.

But then the irq triggers and we try calling complete() on the
context pointer which points to now random stack space, which
results in the panic.

Alan Stern pointed out there is a bug here, in that the snippet
above "assumes that usb_ep_dequeue() waits until the request has
been completed." And that:

    wait_for_completion(&done);

Is needed right after the usb_ep_dequeue().

Thus this patch implements that change. With it I no longer see
the crashes on suspend or reboot.

This issue seems to have been uncovered by behavioral changes in
the dwc3 driver in commit fec9095bdef4e ("usb: dwc3: gadget:
remove wait_end_transfer").

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Zeng Tao <prime.zeng@hisilicon.com>
Cc: Jack Pham <jackp@codeaurora.org>
Cc: Thinh Nguyen <thinh.nguyen@synopsys.com>
Cc: Chen Yu <chenyu56@huawei.com>
Cc: Jerry Zhang <zhangjerry@google.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Vincent Pelletier <plr.vincent@gmail.com>
Cc: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linux USB List <linux-usb@vger.kernel.org>
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 49145924e804 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I5a786991ea9ceef96ff6c6b65dc807f842356fd6

4 years agousb: gadget: f_fs: Only return delayed status when len is 0 98/218598/1
Jerry Zhang [Mon, 2 Jul 2018 19:48:08 +0000 (12:48 -0700)]
usb: gadget: f_fs: Only return delayed status when len is 0

commit 4d644abf25698362bd33d17c9ddc8f7122c30f17 upstream.

Commit 1b9ba000 ("Allow function drivers to pause control
transfers") states that USB_GADGET_DELAYED_STATUS is only
supported if data phase is 0 bytes.

It seems that when the length is not 0 bytes, there is no
need to explicitly delay the data stage since the transfer
is not completed until the user responds. However, when the
length is 0, there is no data stage and the transfer is
finished once setup() returns, hence there is a need to
explicitly delay completion.

This manifests as the following bugs:

Prior to 946ef68ad4e4 ('Let setup() return
USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs
would require user to queue a 0 byte request in order to
clear setup state. However, that 0 byte request was actually
not needed and would hang and cause errors in other setup
requests.

After the above commit, 0 byte setups work since the gadget
now accepts empty queues to ep0 to clear the delay, but all
other setups hang.

Fixes: 946ef68ad4e4 ("Let setup() return USB_GADGET_DELAYED_STATUS")
Signed-off-by: Jerry Zhang <zhangjerry@google.com>
Cc: stable <stable@vger.kernel.org>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 9e10043b6bdc to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: Idf5d504bd5059cc5141f4a3e98c572708c631079

4 years agousb: gadget: ffs: Execute copy_to_user() with USER_DS set 97/218597/1
Lars-Peter Clausen [Fri, 12 Jan 2018 10:05:02 +0000 (11:05 +0100)]
usb: gadget: ffs: Execute copy_to_user() with USER_DS set

[ Upstream commit 4058ebf33cb0be88ca516f968eda24ab7b6b93e4 ]

When using a AIO read() operation on the function FS gadget driver a URB is
submitted asynchronously and on URB completion the received data is copied
to the userspace buffer associated with the read operation.

This is done from a kernel worker thread invoking copy_to_user() (through
copy_to_iter()). And while the user space process memory is made available
to the kernel thread using use_mm(), some architecture require in addition
to this that the operation runs with USER_DS set. Otherwise the userspace
memory access will fail.

For example on ARM64 with Privileged Access Never (PAN) and User Access
Override (UAO) enabled the following crash occurs.

Internal error: Accessing user space memory with fs=KERNEL_DS: 9600004f [#1] SMP
Modules linked in:
CPU: 2 PID: 1636 Comm: kworker/2:1 Not tainted 4.9.0-04081-g8ab2dfb-dirty #487
Hardware name: ZynqMP ZCU102 Rev1.0 (DT)
Workqueue: events ffs_user_copy_worker
task: ffffffc87afc8080 task.stack: ffffffc87a00c000
PC is at __arch_copy_to_user+0x190/0x220
LR is at copy_to_iter+0x78/0x3c8
[...]
[<ffffff800847b790>] __arch_copy_to_user+0x190/0x220
[<ffffff80086f25d8>] ffs_user_copy_worker+0x70/0x130
[<ffffff80080b8c64>] process_one_work+0x1dc/0x460
[<ffffff80080b8f38>] worker_thread+0x50/0x4b0
[<ffffff80080bf5a0>] kthread+0xd8/0xf0
[<ffffff8008083680>] ret_from_fork+0x10/0x50

Address this by placing a set_fs(USER_DS) before of the copy operation
and revert it again once the copy operation has finished.

This patch is analogous to commit d7ffde35e31a ("vhost: use USER_DS in
vhost_worker thread") which addresses the same underlying issue.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 5209c778346a to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: Iee47b31c16c2f83540e4e1f8bd3f3eaebd727ad2

4 years agousb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS 96/218596/1
Lars-Peter Clausen [Fri, 12 Jan 2018 10:26:16 +0000 (11:26 +0100)]
usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS

[ Upstream commit 946ef68ad4e45aa048a5fb41ce8823ed29da866a ]

Some UDC drivers (like the DWC3) expect that the response to a setup()
request is queued from within the setup function itself so that it is
available as soon as setup() has completed.

Upon receiving a setup request the function fs driver creates an event that
is made available to userspace. And only once userspace has acknowledged
that event the response to the setup request is queued.

So it violates the requirement of those UDC drivers and random failures can
be observed. This is basically a race condition and if userspace is able to
read the event and queue the response fast enough all is good. But if it is
not, for example because other processes are currently scheduled to run,
the USB host that sent the setup request will observe an error.

To avoid this the gadget framework provides the USB_GADGET_DELAYED_STATUS
return code. If a setup() callback returns this value the UDC driver is
aware that response is not yet available and can uses the appropriate
methods to handle this case.

Since in the case of function fs the response will never be available when
the setup() function returns make sure that this status code is used.

This fixed random occasional failures that were previously observed on a
DWC3 based system under high system load.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 10be2659c629 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I1b88c4739c9007bfd515b670401035ef2bc541fc

4 years agousb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb() 95/218595/1
Xinyong [Fri, 2 Mar 2018 11:20:07 +0000 (19:20 +0800)]
usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb()

commit 1a087f032111a88e826877449dfb93ceb22b78b9 upstream.

When I debug a kernel crash issue in funcitonfs, found ffs_data.ref
overflowed, While functionfs is unmounting, ffs_data is put twice.

Commit 43938613c6fd ("drivers, usb: convert ffs_data.ref from atomic_t to
refcount_t") can avoid refcount overflow, but that is risk some situations.
So no need put ffs data in ffs_fs_kill_sb, already put in ffs_data_closed.

The issue can be reproduced in Mediatek mt6763 SoC, ffs for ADB device.
KASAN enabled configuration reports use-after-free errro.

BUG: KASAN: use-after-free in refcount_dec_and_test+0x14/0xe0 at addr ffffffc0579386a0
Read of size 4 by task umount/4650
====================================================
BUG kmalloc-512 (Tainted: P        W  O   ): kasan: bad access detected
-----------------------------------------------------------------------------

INFO: Allocated in ffs_fs_mount+0x194/0x844 age=22856 cpu=2 pid=566
    alloc_debug_processing+0x1ac/0x1e8
    ___slab_alloc.constprop.63+0x640/0x648
    __slab_alloc.isra.57.constprop.62+0x24/0x34
    kmem_cache_alloc_trace+0x1a8/0x2bc
    ffs_fs_mount+0x194/0x844
    mount_fs+0x6c/0x1d0
    vfs_kern_mount+0x50/0x1b4
    do_mount+0x258/0x1034
INFO: Freed in ffs_data_put+0x25c/0x320 age=0 cpu=3 pid=4650
    free_debug_processing+0x22c/0x434
    __slab_free+0x2d8/0x3a0
    kfree+0x254/0x264
    ffs_data_put+0x25c/0x320
    ffs_data_closed+0x124/0x15c
    ffs_fs_kill_sb+0xb8/0x110
    deactivate_locked_super+0x6c/0x98
    deactivate_super+0xb0/0xbc
INFO: Object 0xffffffc057938600 @offset=1536 fp=0x          (null)
......
Call trace:
[<ffffff900808cf5c>] dump_backtrace+0x0/0x250
[<ffffff900808d3a0>] show_stack+0x14/0x1c
[<ffffff90084a8c04>] dump_stack+0xa0/0xc8
[<ffffff900826c2b4>] print_trailer+0x158/0x260
[<ffffff900826d9d8>] object_err+0x3c/0x40
[<ffffff90082745f0>] kasan_report_error+0x2a8/0x754
[<ffffff9008274f84>] kasan_report+0x5c/0x60
[<ffffff9008273208>] __asan_load4+0x70/0x88
[<ffffff90084cd81c>] refcount_dec_and_test+0x14/0xe0
[<ffffff9008d98f9c>] ffs_data_put+0x80/0x320
[<ffffff9008d9d904>] ffs_fs_kill_sb+0xc8/0x110
[<ffffff90082852a0>] deactivate_locked_super+0x6c/0x98
[<ffffff900828537c>] deactivate_super+0xb0/0xbc
[<ffffff90082af0c0>] cleanup_mnt+0x64/0xec
[<ffffff90082af1b0>] __cleanup_mnt+0x10/0x18
[<ffffff90080d9e68>] task_work_run+0xcc/0x124
[<ffffff900808c8c0>] do_notify_resume+0x60/0x70
[<ffffff90080866e4>] work_pending+0x10/0x14

Cc: stable@vger.kernel.org
Signed-off-by: Xinyong <xinyong.fang@linux.alibaba.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit dddf4650cf64 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I32845cb6181c82662c8873505c2d9aff3f3f980c

4 years agousb: gadget: f_fs: Process all descriptors during bind 94/218594/1
Jack Pham [Wed, 24 Jan 2018 08:11:53 +0000 (00:11 -0800)]
usb: gadget: f_fs: Process all descriptors during bind

commit 6cf439e0d37463e42784271179c8a308fd7493c6 upstream.

During _ffs_func_bind(), the received descriptors are evaluated
to prepare for binding with the gadget in order to allocate
endpoints and optionally set up OS descriptors. However, the
high- and super-speed descriptors are only parsed based on
whether the gadget_is_dualspeed() and gadget_is_superspeed()
calls are true, respectively.

This is a problem in case a userspace program always provides
all of the {full,high,super,OS} descriptors when configuring a
function. Then, for example if a gadget device is not capable
of SuperSpeed, the call to ffs_do_descs() for the SS descriptors
is skipped, resulting in an incorrect offset calculation for
the vla_ptr when moving on to the OS descriptors that follow.
This causes ffs_do_os_descs() to fail as it is now looking at
the SS descriptors' offset within the raw_descs buffer instead.

_ffs_func_bind() should evaluate the descriptors unconditionally,
so remove the checks for gadget speed.

Fixes: f0175ab51993 ("usb: gadget: f_fs: OS descriptors support")
Cc: stable@vger.kernel.org
Co-Developed-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 8bedacf13d59 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I0ed8330a0e692ea80263f31b7804203edfbd2d4d

4 years agousb: f_fs: Prevent gadget unbind if it is already unbound 93/218593/1
Hemant Kumar [Tue, 9 Jan 2018 07:00:53 +0000 (12:30 +0530)]
usb: f_fs: Prevent gadget unbind if it is already unbound

commit ce5bf9a50daf2d9078b505aca1cea22e88ecb94a upstream.

Upon usb composition switch there is possibility of ep0 file
release happening after gadget driver bind. In case of composition
switch from adb to a non-adb composition gadget will never gets
bound again resulting into failure of usb device enumeration. Fix
this issue by checking FFS_FL_BOUND flag and avoid extra
gadget driver unbind if it is already done as part of composition
switch.

This fixes adb reconnection error reported on Android running
v4.4 and above kernel versions. Verified on Hikey running vanilla
v4.15-rc7 + few out of tree Mali patches.

Reviewed-at: https://android-review.googlesource.com/#/c/582632/

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg KH <gregkh@linux-foundation.org>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Dmitry Shmidt <dimitrysh@google.com>
Cc: Badhri <badhri@google.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
[AmitP: Cherry-picked it from android-4.14 and updated the commit log]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit f24d171a8100 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: Ifbab9f182fa3779c57ab288958553c3711d50e28

4 years agousb: gadget: ffs: Forbid usb_ep_alloc_request from sleeping 92/218592/1
Vincent Pelletier [Sun, 26 Nov 2017 06:52:53 +0000 (06:52 +0000)]
usb: gadget: ffs: Forbid usb_ep_alloc_request from sleeping

commit 30bf90ccdec1da9c8198b161ecbff39ce4e5a9ba upstream.

Found using DEBUG_ATOMIC_SLEEP while submitting an AIO read operation:

[  100.853642] BUG: sleeping function called from invalid context at mm/slab.h:421
[  100.861148] in_atomic(): 1, irqs_disabled(): 1, pid: 1880, name: python
[  100.867954] 2 locks held by python/1880:
[  100.867961]  #0:  (&epfile->mutex){....}, at: [<f8188627>] ffs_mutex_lock+0x27/0x30 [usb_f_fs]
[  100.868020]  #1:  (&(&ffs->eps_lock)->rlock){....}, at: [<f818ad4b>] ffs_epfile_io.isra.17+0x24b/0x590 [usb_f_fs]
[  100.868076] CPU: 1 PID: 1880 Comm: python Not tainted 4.14.0-edison+ #118
[  100.868085] Hardware name: Intel Corporation Merrifield/BODEGA BAY, BIOS 542 2015.01.21:18.19.48
[  100.868093] Call Trace:
[  100.868122]  dump_stack+0x47/0x62
[  100.868156]  ___might_sleep+0xfd/0x110
[  100.868182]  __might_sleep+0x68/0x70
[  100.868217]  kmem_cache_alloc_trace+0x4b/0x200
[  100.868248]  ? dwc3_gadget_ep_alloc_request+0x24/0xe0 [dwc3]
[  100.868302]  dwc3_gadget_ep_alloc_request+0x24/0xe0 [dwc3]
[  100.868343]  usb_ep_alloc_request+0x16/0xc0 [udc_core]
[  100.868386]  ffs_epfile_io.isra.17+0x444/0x590 [usb_f_fs]
[  100.868424]  ? _raw_spin_unlock_irqrestore+0x27/0x40
[  100.868457]  ? kiocb_set_cancel_fn+0x57/0x60
[  100.868477]  ? ffs_ep0_poll+0xc0/0xc0 [usb_f_fs]
[  100.868512]  ffs_epfile_read_iter+0xfe/0x157 [usb_f_fs]
[  100.868551]  ? security_file_permission+0x9c/0xd0
[  100.868587]  ? rw_verify_area+0xac/0x120
[  100.868633]  aio_read+0x9d/0x100
[  100.868692]  ? __fget+0xa2/0xd0
[  100.868727]  ? __might_sleep+0x68/0x70
[  100.868763]  SyS_io_submit+0x471/0x680
[  100.868878]  do_int80_syscall_32+0x4e/0xd0
[  100.868921]  entry_INT80_32+0x2a/0x2a
[  100.868932] EIP: 0xb7fbb676
[  100.868941] EFLAGS: 00000292 CPU: 1
[  100.868951] EAX: ffffffda EBX: b7aa2000 ECX: 00000002 EDX: b7af8368
[  100.868961] ESI: b7fbb660 EDI: b7aab000 EBP: bfb6c658 ESP: bfb6c638
[  100.868973]  DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 007b

Signed-off-by: Vincent Pelletier <plr.vincent@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 16648cbcd332 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I7716588e2a674be3f5f602273fd283273b87b730

4 years agousb: f_fs: Force Reserved1=1 in OS_DESC_EXT_COMPAT 91/218591/1
John Keeping [Mon, 27 Nov 2017 18:15:40 +0000 (18:15 +0000)]
usb: f_fs: Force Reserved1=1 in OS_DESC_EXT_COMPAT

commit a3acc696085e112733d191a77b106e67a4fa110b upstream.

The specification says that the Reserved1 field in OS_DESC_EXT_COMPAT
must have the value "1", but when this feature was first implemented we
rejected any non-zero values.

This was adjusted to accept all non-zero values (while now rejecting
zero) in commit 53642399aa71 ("usb: gadget: f_fs: Fix wrong check on
reserved1 of OS_DESC_EXT_COMPAT"), but that breaks any userspace
programs that worked previously by returning EINVAL when Reserved1 == 0
which was previously the only value that succeeded!

If we just set the field to "1" ourselves, both old and new userspace
programs continue to work correctly and, as a bonus, old programs are
now compliant with the specification without having to fix anything
themselves.

Fixes: 53642399aa71 ("usb: gadget: f_fs: Fix wrong check on reserved1 of OS_DESC_EXT_COMPAT")
Signed-off-by: John Keeping <john@metanate.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 112b8a8f558d to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I00f7fce7bc2c5225c3f9ec00f30d1e4f4f0582de

4 years agousb: gadget: f_fs: Fix ExtCompat descriptor validation 90/218590/1
Vincent Pelletier [Thu, 15 Dec 2016 12:47:42 +0000 (12:47 +0000)]
usb: gadget: f_fs: Fix ExtCompat descriptor validation

[ Upstream commit 354bc45bf329494ef6051f3229ef50b9e2a7ea2a ]

Reserved1 is documented as expected to be set to 0, but this test fails
when it it set to 0. Reverse the condition.

Signed-off-by: Vincent Pelletier <plr.vincent@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit 5eb97be87981 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: Id8bd89a9cb5343fd0830d480ad5b2900367d8056

4 years agousb: gadget: f_fs: Fix use-after-free in ffs_free_inst 89/218589/1
Andrew Gabbasov [Wed, 8 Nov 2017 17:13:15 +0000 (10:13 -0700)]
usb: gadget: f_fs: Fix use-after-free in ffs_free_inst

commit cdafb6d8b8da7fde266f79b3287ac221aa841879 upstream.

KASAN enabled configuration reports an error

BUG: KASAN: use-after-free in ffs_free_inst+... [usb_f_fs] at addr ...
Write of size 8 by task ...

This is observed after "ffs-test" is run and interrupted. If after that
functionfs is unmounted and g_ffs module is unloaded, that use-after-free
occurs during g_ffs module removal.

Although the report indicates ffs_free_inst() function, the actual
use-after-free condition occurs in _ffs_free_dev() function, which
is probably inlined into ffs_free_inst().

This happens due to keeping the ffs_data reference in device structure
during functionfs unmounting, while ffs_data itself is freed as no longer
needed. The fix is to clear that reference in ffs_closed() function,
which is a counterpart of ffs_ready(), where the reference is stored.

Fixes: 3262ad824307 ("usb: gadget: f_fs: Stop ffs_closed NULL pointer dereference")
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[dwoo08.lee: cherry-pick linux-4.9.y stable commit fd6a742d8bf7 to stablize f_fs]
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Change-Id: I6e32305fee754d8a11eaa0650319e8e620d4c2af

4 years ago[LOCAL] arm64/ptrace: Add compat FPR register support 37/218037/2 accepted/tizen/unified/20191121.154757 submit/tizen/20191121.072817
Seung-Woo Kim [Tue, 19 Nov 2019 01:21:01 +0000 (10:21 +0900)]
[LOCAL] arm64/ptrace: Add compat FPR register support

From aarch32 ptrace view, fpr register support is done with vfp
registers. As like aarch32 ptrace view, Add to suppot compat fpr
resister with vfp.

Change-Id: If5b4b6b5f33b7691ba9d3b65c1bffcf316e19588
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years ago[LOCAL] arm64: perf: Report arm pc registers for compat perf 36/218036/2
Seung-Woo Kim [Wed, 11 Dec 2019 00:57:56 +0000 (09:57 +0900)]
[LOCAL] arm64: perf: Report arm pc registers for compat perf

If perf is built as arm 32-bit, it only reads 15 registers as arm
32-bit register map and this breaks dwarf call-chain in compat
perf because pc register information is not filled.
Report arm pc registers for 32-bit compat perf.

Without this, arm 32-bit perf dwarf call-graph shows below
verbose message:
  unwind: reg 15, val 0
  unwind: reg 13, val ffbc6360
  unwind: no map for 0

Posted to mainline[1] but never merged.

[1]: https://patchwork.kernel.org/patch/11238463/
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I8c35067224707b3077d7bfd14efda7c20c8d2869

4 years agoarm64: ftrace: don't adjust the LR value 71/218071/1
Mark Rutland [Thu, 15 Nov 2018 22:42:01 +0000 (22:42 +0000)]
arm64: ftrace: don't adjust the LR value

[ Upstream commit 6e803e2e6e367db9a0d6ecae1bd24bb5752011bd ]

The core ftrace code requires that when it is handed the PC of an
instrumented function, this PC is the address of the instrumented
instruction. This is necessary so that the core ftrace code can identify
the specific instrumentation site. Since the instrumented function will
be a BL, the address of the instrumented function is LR - 4 at entry to
the ftrace code.

This fixup is applied in the mcount_get_pc and mcount_get_pc0 helpers,
which acquire the PC of the instrumented function.

The mcount_get_lr helper is used to acquire the LR of the instrumented
function, whose value does not require this adjustment, and cannot be
adjusted to anything meaningful. No adjustment of this value is made on
other architectures, including arm. However, arm64 adjusts this value by
4.

This patch brings arm64 in line with other architectures and removes the
adjustment of the LR value.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[sw0312.kim: cherry-pick linux-4.9.y stable commit bfadca610fcf to fix ftrace issue]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ib9a2bd4728efeb0b1fa28e60135ba596bac55ace

4 years agoarm64: Fix static use of function graph 70/218070/1
Julien Thierry [Fri, 3 Nov 2017 11:44:16 +0000 (11:44 +0000)]
arm64: Fix static use of function graph

Function graph does not work currently when CONFIG_DYNAMIC_TRACE is not
set. This is because ftrace_function_trace is not always set to ftrace_stub
when function_graph is in use.

Do not skip checking of graph tracer functions when ftrace_function_trace
is set.

Signed-off-by: Julien Thierry <julien.thierry@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
[sw0312.kim: cherry-pick mainline commit d125bffcefb2 to fix function_graph without CONFIG_DYNAMIC_TRACE]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I7eddd61e45ed2f459bd70785126eaf551ee7a3d2

4 years agoarm64: include asm/assembler.h in entry-ftrace.S 69/218069/1
Arnd Bergmann [Tue, 14 Feb 2017 21:32:58 +0000 (22:32 +0100)]
arm64: include asm/assembler.h in entry-ftrace.S

In a randconfig build I ran into this build error:

arch/arm64/kernel/entry-ftrace.S: Assembler messages:
arch/arm64/kernel/entry-ftrace.S:101: Error: unknown mnemonic `ldr_l' -- `ldr_l x2,ftrace_trace_function'

The macro is defined in asm/assembler.h, so we should include that file.

Fixes: 829d2bd13392 ("arm64: entry-ftrace.S: avoid open-coded {adr,ldr}_l")
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Will Deacon <will.deacon@arm.com>
[sw0312.kim: cherry-pick mainline commit f705d954634d to apply function_graph related patch]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ifeb122550ece026c45bd5509f0ba86adb0228e24

4 years agoarm64: entry-ftrace.S: avoid open-coded {adr,ldr}_l 68/218068/1
Mark Rutland [Tue, 17 Jan 2017 16:10:58 +0000 (16:10 +0000)]
arm64: entry-ftrace.S: avoid open-coded {adr,ldr}_l

Some places in the kernel open-code sequences using ADRP for a symbol
another instruction using a :lo12: relocation for that same symbol.
These sequences are easy to get wrong, and more painful to read than is
necessary. For these reasons, it is preferable to use the
{adr,ldr,str}_l macros for these cases.

This patch makes use of these in entry-ftrace.S, removing open-coded
sequences using adrp. This results in a minor code change, since a
temporary register is not used when generating the address for some
symbols, but this is fine, as the value of the temporary register is not
used elsewhere.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
[sw0312.kim: cherry-pick mainline commit 829d2bd13392 to apply function_graph related patch]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I72fa3cbcf569f679b13f436b35793e69725849d4

4 years agoarm64: tizen_tw3_defconfig: Enable FTRACE 18/216718/4
Seung-Woo Kim [Thu, 31 Oct 2019 05:21:14 +0000 (14:21 +0900)]
arm64: tizen_tw3_defconfig: Enable FTRACE

Enable FTRACE with FUNCTION_TRACE and FUNCION_GRAHPIC_TRACER for
config options to support function trace.

Change-Id: I5617579549cd8e1579e076a92e4a4bb11a2878dc
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoarm64: make secondary_start_kernel() notrace 99/217799/2
Zhizhou Zhang [Tue, 12 Jun 2018 09:07:37 +0000 (17:07 +0800)]
arm64: make secondary_start_kernel() notrace

[ Upstream commit b154886f7892499d0d3054026e19dfb9a731df61 ]

We can't call function trace hook before setup percpu offset.
When entering secondary_start_kernel(), percpu offset has not
been initialized.  So this lead hotplug malfunction.
Here is the flow to reproduce this bug:

echo 0 > /sys/devices/system/cpu/cpu1/online
echo function > /sys/kernel/debug/tracing/current_tracer
echo 1 > /sys/kernel/debug/tracing/tracing_on
echo 1 > /sys/devices/system/cpu/cpu1/online

Acked-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Zhizhou Zhang <zhizhouzhang@asrmicro.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: apply stable linux-4.9.y commit 40137ff99323 to fix ftrace issue]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I1bb45adfe88a4284561cde6d1a1bb31951a2d677

4 years agostaging: samsung: add build dependency for SEC_DUMP_SUMMARY to SEC_DEBUG 86/217786/1
Seung-Woo Kim [Thu, 14 Nov 2019 07:22:44 +0000 (16:22 +0900)]
staging: samsung: add build dependency for SEC_DUMP_SUMMARY to SEC_DEBUG

The SEC_DUMP_SUMMARY is inside of sec_debug driver, so the option
should be dependent on SEC_DEBUG. Add the build dependency.

Change-Id: I4a0d338e27c29f4d01c84435d69099f17fbb7ef1
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agowatchdog: s3c2410: Fix build issue without EXYNOS_SNAPSHOT 85/217785/1
Seung-Woo Kim [Thu, 14 Nov 2019 07:28:43 +0000 (16:28 +0900)]
watchdog: s3c2410: Fix build issue without EXYNOS_SNAPSHOT

The watchdog driver can be used without CONFIG_EXYNOS_SNAPSHOT,
but some s3c watchdog functions are dependent on the config.
Fix build issue without CONFIG_EXYNOS_SNAPSHOT.

Change-Id: I9f846c99fc5a7dfea95c5e4835dcf1336d8cf7e9
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agosensorhub: Fix input notify dependency to SEC_DEBUG 84/217784/1
Seung-Woo Kim [Thu, 14 Nov 2019 07:31:38 +0000 (16:31 +0900)]
sensorhub: Fix input notify dependency to SEC_DEBUG

The input notify can be used outside of SEC_DEBUG, but its enum is
defiend inside of SEC_DEBUG. Fix the input notify dependency to
SEC_DEBUG.

Change-Id: Iabec8761f23404e6c08436b07a149ea7b760827a
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agosensorhub: remove unused variable without SSP_SEC_DEBUG option 83/217783/1
Seung-Woo Kim [Thu, 14 Nov 2019 07:24:59 +0000 (16:24 +0900)]
sensorhub: remove unused variable without SSP_SEC_DEBUG option

If not using SSP_SEC_DEBUG, there is unused variable backup_fs.
Remove the unused variable.

Change-Id: Ib64f940e9a3c5080eb75255a218c01eb09373588
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoarm64: tizen_tw3_defconfig: Enable CONFIG_CRYPTO_USER_API 14/217614/1 accepted/tizen/unified/20191113.123430 submit/tizen/20191113.062026
DoHyun Pyun [Wed, 13 Nov 2019 04:26:44 +0000 (13:26 +0900)]
arm64: tizen_tw3_defconfig: Enable CONFIG_CRYPTO_USER_API

Enable CONFIG_CRYPTO_USER_API config options to use CRYPTO
API from userspace. ALG(Algorithm) socket will be used for
BLE Mesh functionality by bluez.

Change-Id: Iaa07610176bba04a301449fdee5446f36124eb3e
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
4 years agoBluetooth: Do not update background scan when updating connectable 29/217529/1
Deokhyun Kim [Tue, 12 Nov 2019 07:44:09 +0000 (16:44 +0900)]
Bluetooth: Do not update background scan when updating connectable

Scan should be kept even though connectable is changed, because it may not be
a scan for connection.

Change-Id: I87b5d76c86c786de712dad4c801e8642d8cd885a
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
4 years agoInput: s2mpw02-power-key: support back key boost 15/216715/1 accepted/tizen/unified/20191106.124703 submit/tizen/20191106.012900
Seung-Woo Kim [Thu, 31 Oct 2019 02:29:13 +0000 (11:29 +0900)]
Input: s2mpw02-power-key: support back key boost

Now, keymap can be changed and it is mainly for using back key
instead of power key. So as like gpio-keys, it needs to consider
back key boost. Support back key boost like gpio-keys.

Change-Id: I22826afcbbe3ba933a63e9f9106f8d05e3767f3b
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoInput: s2mpw02-power-key: support setkeycode 14/216714/1
Seung-Woo Kim [Thu, 31 Oct 2019 01:39:31 +0000 (10:39 +0900)]
Input: s2mpw02-power-key: support setkeycode

Add support for input_setkeycode to the s2mpw02-power-key driver
for using the udev hwdb mechanism to change keymap.

Change-Id: I581c12ae32595b04b90c4685d9fa0a6aed501f2f
Reference: 4b17f91b1677 ("Input: gpio-keys - add support for setkeycode")
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agoInput: gpio-keys - add support for setkeycode 13/216713/1
Hans de Goede [Thu, 31 Oct 2019 01:39:13 +0000 (10:39 +0900)]
Input: gpio-keys - add support for setkeycode

gpio-keys input devices created by the soc_button_array driver are
configured with key-codes based on ACPI provided information.

Unfortunately on some tablets this info is wrong, and we need to have
a quirk to fix things up.

Add support for input_setkeycode to the gpio-keys driver, so that
the existing udev hwdb mechanism can be used to fix things up on these
tablets.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
[sw0312.kim: backport mainline commit 83e4947a569f to suuport setkeycode]
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83e4947a569f4d544ef4a1361f51c91d73a9c915
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ia21dbdb9591b7a83989dfcba561eb5a4cf846ade

4 years agosoc: samsung: cal-if: exynos9110: remove clocks for secure world 47/216247/3 tizen_5.5_tv accepted/tizen/5.5/unified/20191115.093732 accepted/tizen/unified/20191101.042028 submit/tizen/20191031.012258 submit/tizen/20191031.023155 submit/tizen/20191031.111959 submit/tizen_5.5/20191115.014019
Seung-Woo Kim [Tue, 22 Oct 2019 08:46:13 +0000 (17:46 +0900)]
soc: samsung: cal-if: exynos9110: remove clocks for secure world

In exynos9110, some clocks are protected by trustzone secure world,
and accessing them causes system abort. Not to access the clocks from
kernel in normal world, remove the clocks protected by secure
world including ispp, vts, mfcmscl, g3dp, chubp.

Change-Id: I6ef4de7bbb77f50492cc34f90f7e012fa55395cf
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agosoc: samsung: cal-if: exynos9110: remove a clock for unassigned block 46/216246/2
Seung-Woo Kim [Tue, 22 Oct 2019 10:45:52 +0000 (19:45 +0900)]
soc: samsung: cal-if: exynos9110: remove a clock for unassigned block

From exynos9110 clock sfr, sfr of BLK_MODEM is set as just 0 and
that means it is not assigned. Accessing clock for the block
causes memory abort accessing wrong address. So remove the clock
for unassigned modem block.

Change-Id: Id880ed48ef8d01f4d8c348642fdcffc4004997fd
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
4 years agovideo: fbdev: exynos: dpu9110: fix null pointer deference for recovery_cnt 72/216172/1
Seung-Woo Kim [Tue, 22 Oct 2019 01:52:24 +0000 (10:52 +0900)]
video: fbdev: exynos: dpu9110: fix null pointer deference for recovery_cnt

There is no drvdata for specific instance of dpp when it is not
assigned from dt, and accessing it without null check causes null
pointer deference. Fix the null pointer defercens when accessing
recovery_cnt.

Change-Id: Ie57024101d461b1135f341bd1f76b55d0d77ec73
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agoarm64: tizen_tw3_defconfig: Enable NETFILTER_XT_MATCH_OWNER config 28/211228/1 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.032629 accepted/tizen/5.5/unified/mobile/hotfix/20201027.060924 accepted/tizen/unified/20190801.113445 submit/tizen/20190801.010047 submit/tizen_5.5/20191031.000010 submit/tizen_5.5/20191031.000011 submit/tizen_5.5/20191031.000013 submit/tizen_5.5_mobile_hotfix/20201026.1851010 submit/tizen_5.5_mobile_hotfix/20201027.114301 tizen_5.5.m2_release
Seung-Woo Kim [Wed, 31 Jul 2019 07:31:01 +0000 (16:31 +0900)]
arm64: tizen_tw3_defconfig: Enable NETFILTER_XT_MATCH_OWNER config

Enable the NETFILTER_XT_MATCH_OWNER config option to use xt_owner
supplementary groups.

Change-Id: I3c40c2d41dd29eede403f430887aab8f1ee4eaea
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agonetfilter: xt_owner: bail out with EINVAL in case of unsupported flags 03/209203/1 accepted/tizen/unified/20190705.110614 submit/tizen/20190705.061120
Pablo Neira Ayuso [Fri, 7 Jun 2019 14:37:30 +0000 (16:37 +0200)]
netfilter: xt_owner: bail out with EINVAL in case of unsupported flags

Reject flags that are not supported with EINVAL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
[sw0312.kim: backport from mainline to support supplementary groups on netfilter]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I178cb193c6593b40d004e3110e512fcd5627d125

5 years agonetfilter: xt_owner: Add supplementary groups option 02/209202/1
Lukasz Pawelczyk [Fri, 10 May 2019 11:46:22 +0000 (13:46 +0200)]
netfilter: xt_owner: Add supplementary groups option

The XT_OWNER_SUPPL_GROUPS flag causes GIDs specified with XT_OWNER_GID
to be also checked in the supplementary groups of a process.

f_cred->group_info cannot be modified during its lifetime and f_cred
holds a reference to it so it's safe to use.

Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
[sw0312.kim: backport from mainline to support supplementary groups on netfilter]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: If8a18f3c90378800fdee702c4eb0d7ec7c8c744e

5 years agoarm64: dts: exynos: Support offload playback 17/206217/4 accepted/tizen/unified/20190602.221819 submit/tizen/20190530.011954
Jaechul Lee [Wed, 15 May 2019 07:17:02 +0000 (16:17 +0900)]
arm64: dts: exynos: Support offload playback

Change-Id: I9a000740ef332018484f4a055baa700b27093821
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
5 years agoscript: release.sh: allow the local build on 32bit machine 07/199307/1
Jaehoon Chung [Fri, 8 Feb 2019 09:39:50 +0000 (18:39 +0900)]
script: release.sh: allow the local build on 32bit machine

Allow the local build on 32bit machine, not only 64bit machine.

Change-Id: I7b8d9769bb1426b41ebde7b4eb8a5a74b6c3d5d6
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agodrm/tgm: tdm_pp: fix not to call sync fence without fence/dma_buf 53/197353/1 accepted/tizen/unified/20190114.060130 submit/tizen/20190111.030902
Hoegeun Kwon [Fri, 11 Jan 2019 00:55:37 +0000 (09:55 +0900)]
drm/tgm: tdm_pp: fix not to call sync fence without fence/dma_buf

When without fence or dma_buf, tdm_pp tries to call sync fence and
it causes null deference or not necessary error message. Fix not
to call sync fence without fence or dma_buf.

Change-Id: Ic762185f1934c7dd0489a2dc8332d5bace29bae5
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Hoegeun Kwon <hoegeun.kwon@samsung.com>
5 years agoarm64: tizen_tw3_defconfig: enable SECURITY_SMACK_APPEND_SIGNALS 30/197030/2 accepted/tizen/unified/20190110.060355 submit/tizen/20190109.063522
Seung-Woo Kim [Wed, 9 Jan 2019 03:51:56 +0000 (12:51 +0900)]
arm64: tizen_tw3_defconfig: enable SECURITY_SMACK_APPEND_SIGNALS

Enable SECURITY_SMACK_APPEND_SIGNALS to allow smack rules denying
signal delivery while allowing IPC in Tizen.

Change-Id: If438465b6ced7f529baf69754555778eb554c6c5
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agoarm64: tizen_tw3_defconfig: enable CONNECTOR and PROC_EVENTS options 29/197029/2
Seung-Woo Kim [Wed, 9 Jan 2019 03:45:55 +0000 (12:45 +0900)]
arm64: tizen_tw3_defconfig: enable CONNECTOR and PROC_EVENTS options

These options enable Netlink Connector feature of kernel to monitor
process lifecycle like Fork and Exit status of all processes
asynchronously.

In Tzen, it will be used by stc-manager(smart traffic control) to
monitor process lifecycle.

Change-Id: I265504609e6b2ce963875e66884d064affc48d9d
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agoproc, coredump: add CoreDumping flag to /proc/pid/status 28/197028/2
Roman Gushchin [Fri, 17 Nov 2017 23:26:45 +0000 (15:26 -0800)]
proc, coredump: add CoreDumping flag to /proc/pid/status

Right now there is no convenient way to check if a process is being
coredumped at the moment.

It might be necessary to recognize such state to prevent killing the
process and getting a broken coredump.  Writing a large core might take
significant time, and the process is unresponsive during it, so it might
be killed by timeout, if another process is monitoring and
killing/restarting hanging tasks.

We're getting a significant number of corrupted coredump files on
machines in our fleet, just because processes are being killed by
timeout in the middle of the core writing process.

We do have a process health check, and some agent is responsible for
restarting processes which are not responding for health check requests.
Writing a large coredump to the disk can easily exceed the reasonable
timeout (especially on an overloaded machine).

This flag will allow the agent to distinguish processes which are being
coredumped, extend the timeout for them, and let them produce a full
coredump file.

To provide an ability to detect if a process is in the state of being
coredumped, we can expose a boolean CoreDumping flag in
/proc/pid/status.

Example:
$ cat core.sh
  #!/bin/sh

  echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern
  sleep 1000 &
  PID=$!

  cat /proc/$PID/status | grep CoreDumping
  kill -ABRT $PID
  sleep 1
  cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping: 0
  CoreDumping: 1

[guro@fb.com: document CoreDumping flag in /proc/<pid>/status]
Link: http://lkml.kernel.org/r/20170928135357.GA8470@castle.DHCP.thefacebook.com
Link: http://lkml.kernel.org/r/20170920230634.31572-1-guro@fb.com
Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[sw0312.kim: backport mainline commit c643401218be to allow Tizen system recognizes coredump status]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I32d92f59d203b9ff081420b95ad2f8329893657f

5 years agoSmack: ignore private inode for file functions 27/197027/2
Seung-Woo Kim [Mon, 12 Dec 2016 08:35:26 +0000 (17:35 +0900)]
Smack: ignore private inode for file functions

The access to fd from anon_inode is always failed because there is
no set xattr operations. So this patch fixes to ignore private
inode including anon_inode for file functions.

It was only ignored for smack_file_receive() to share dma-buf fd,
but dma-buf has other functions like ioctl and mmap.

Reference: https://lkml.org/lkml/2015/4/17/16

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
[sw0312.kim: backport mainline commit 83a1e53f3920 for Tizen security smack]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I31719d13885b63ebd643fe03565314ad7d65ee3c

5 years agoSmack: fix d_instantiate logic for sockfs and pipefs 26/197026/2
Rafal Krypa [Fri, 9 Dec 2016 13:03:04 +0000 (14:03 +0100)]
Smack: fix d_instantiate logic for sockfs and pipefs

Since 4b936885a (v2.6.32) all inodes on sockfs and pipefs are disconnected.
It caused filesystem specific code in smack_d_instantiate to be skipped,
because all inodes on those pseudo filesystems were treated as root inodes.
As a result all sockfs inodes had the Smack label set to floor.

In most cases access checks for sockets use socket_smack data so the inode
label is not important. But there are special cases that were broken.
One example would be calling fcntl with F_SETOWN command on a socket fd.

Now smack_d_instantiate expects all pipefs and sockfs inodes to be
disconnected and has the logic in appropriate place.

Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
[sw0312.kim: backport mainline commit 805b65a80bed for Tizen security smack]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ib60a38ea4173df99ef1998e4ef5eba215a63c38a

5 years agoASoC: samsung: abox:changes ABOX_ROUTE_CTRL1 initial value 07/197007/1
Jaechul Lee [Wed, 9 Jan 2019 00:52:06 +0000 (09:52 +0900)]
ASoC: samsung: abox:changes ABOX_ROUTE_CTRL1 initial value

ABOX_ROUTE_CTRL1 register needs to be set UAIF0(0x8) because pulseaudio
fails to load the source module at booting.

Change-Id: Ia38aaa925fe542edeeccee860c19f0a9368fc870
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
5 years agoARM64: tizen_tw3_defconfig: enable MODULES 91/196791/1 accepted/tizen/unified/20190107.065510 submit/tizen/20190107.021540
Seung-Woo Kim [Fri, 4 Jan 2019 06:59:39 +0000 (15:59 +0900)]
ARM64: tizen_tw3_defconfig: enable MODULES

To support kernel modules build, loading, and unloading enable config
option MODULES and force loading and unloading options.

Note: in tizen, to support swap-modules, it is required to support
kernel module build.

Change-Id: If67e5a8c5ae91c632a3225244a385ac9ff26728b
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agokconfig: fix not to select TIMA_LKMAUTH from MODULES 90/196790/1
Seung-Woo Kim [Fri, 4 Jan 2019 06:56:18 +0000 (15:56 +0900)]
kconfig: fix not to select TIMA_LKMAUTH from MODULES

TIMA_LKMAUTH prevents loading modules built for development. Fix
not to select TIMA_LKMAUTH by selecting MODULES for possibility
to set the config option.

Change-Id: I65b084ff31e7428296d8995ecb1a9c7a005118c8
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agoarm64: tizen_tw3_defconfig: disable SWAP_DA config. 89/196789/1
Seung-Woo Kim [Fri, 4 Jan 2019 07:35:32 +0000 (16:35 +0900)]
arm64: tizen_tw3_defconfig: disable SWAP_DA config.

To use swap-modules instead of in-tree SWAP_DA, disable related
configs.

Change-Id: I773919821d2e3443878b44672b1d67617f425e8c
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agosensorhub: remove unreachable log printing 92/195692/1 accepted/tizen/unified/20181218.063121 submit/tizen/20181217.231705
Seung-Woo Kim [Mon, 17 Dec 2018 08:42:04 +0000 (17:42 +0900)]
sensorhub: remove unreachable log printing

Remove unreachable log printing which causes build warning with
-Wswitch-unreachable.

Change-Id: I7775546c9aabf588169ff7facfeba598d6a62a9f
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agonet: bcmdhd: remove gcc 7 build warnings 91/195691/1
Seung-Woo Kim [Thu, 6 Sep 2018 02:00:16 +0000 (11:00 +0900)]
net: bcmdhd: remove gcc 7 build warnings

Remove following gcc 7 build warnings:
   drivers/net/wireless/bcmdhd/dhd_common.c: In function ‘dhd_pktfilter_offload_set’:
   drivers/net/wireless/bcmdhd/dhd_common.c:3015:16: error: comparison between pointer and zero character constant [-Werror=pointer-compare]
       if (argv[i] == '\0') {
                   ^~
   drivers/net/wireless/bcmdhd/dhd_common.c:3015:8: note: did you mean to dereference the pointer?
       if (argv[i] == '\0') {
           ^
   drivers/net/wireless/bcmdhd/dhd_rtt.c: In function ‘dhd_rtt_init’:
   drivers/net/wireless/bcmdhd/dhd_rtt.c:983:56: error: ‘subcmd_info.version’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     *out_version = (ret == BCME_OK) ? subcmd_info.version : 0;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/net/wireless/bcmdhd/dhd_rtt.c:977:20: note: ‘subcmd_info.version’ was declared here
     ftm_subcmd_info_t subcmd_info;
                       ^~~~~~~~~~~

Change-Id: I5990eaba2272ecb9633bb0058668eb426fc99d2e
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agoInput: zxt_ztm620_ts: fix incorrect memset size parameter 90/195690/1
Seung-Woo Kim [Mon, 17 Dec 2018 08:34:36 +0000 (17:34 +0900)]
Input: zxt_ztm620_ts: fix incorrect memset size parameter

Fix incorrect memset size parameter which caueses build warnings
for -Wmemset-elt-size.

Change-Id: I15b8014149eb52106ebc7ddd7412acb50cfe0464
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agopackaging: exclude arch for non arm 69/195669/1
Seung-Woo Kim [Mon, 17 Dec 2018 07:27:31 +0000 (16:27 +0900)]
packaging: exclude arch for non arm

For tw3, it is not required to build on non arm arch. exclude non
arm arch by adding ExclusiveArch: armv7l and aarch64.

Note: for aarch64, it really builds binary and for armv7l, only
headers package is built.

Change-Id: I5c4f15a997aec1da3e7d89509f3affd0dc43ff5e
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
5 years agopackaging: added baselibs.conf for building armv7l arch 08/195408/1 accepted/tizen/unified/20181217.064608 submit/tizen/20181213.074704 submit/tizen/20181213.103615
Jaehoon Chung [Thu, 13 Dec 2018 07:30:03 +0000 (16:30 +0900)]
packaging: added baselibs.conf for building armv7l arch

It also needs to build kernel based on armv7l.

Change-Id: Ic04336b57d5f60e8bcad31b710a2056d1e116e33
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoARM64: configs: tizen_tw3_defconfig: disable modem interface config 74/195174/1
Jaehoon Chung [Tue, 11 Dec 2018 07:57:53 +0000 (16:57 +0900)]
ARM64: configs: tizen_tw3_defconfig: disable modem interface config

Disable modem interface configurations.
This config is based on galileo large config.
(Previous config was based on galileo large lte na.)

Change-Id: If3de5097a78e258f8ffbba4c16977e0337a7f0e4
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agopackaging: use upstream tags with .gbs.conf accepted/tizen/unified/20181211.141059 submit/tizen/20181210.095447
Jaehoon Chung [Thu, 6 Dec 2018 22:58:27 +0000 (07:58 +0900)]
packaging: use upstream tags with .gbs.conf

To build properly with upstream version tag in obs, add .gbs.conf.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoARM64: defconfig: use the bootloader's cmmdline
Jaehoon Chung [Wed, 5 Dec 2018 01:01:01 +0000 (10:01 +0900)]
ARM64: defconfig: use the bootloader's cmmdline

Use bootloader's cmdline.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agopackaging: spec: modify linux-4.9-exynos9110 spec file for gbs build
Jaehoon Chung [Mon, 3 Dec 2018 11:58:48 +0000 (20:58 +0900)]
packaging: spec: modify linux-4.9-exynos9110 spec file for gbs build

Modify linux-4.9-exynos9110 file for gbs build.
It refers to tw2 spec.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoscript: release_obs.sh: change to more simple build script
Jaehoon Chung [Mon, 3 Dec 2018 11:56:56 +0000 (20:56 +0900)]
script: release_obs.sh: change to more simple build script

Change to more simple build script for obs.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoscript: release.sh: use tizen_tw3_defconfig
Jaehoon Chung [Mon, 3 Dec 2018 11:04:55 +0000 (20:04 +0900)]
script: release.sh: use tizen_tw3_defconfig

Use tizen_tw3_defconfig instead of variant kconfig.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoARM64: configs: add tizen_tw3_defconfig file
Jaehoon Chung [Mon, 3 Dec 2018 10:52:53 +0000 (19:52 +0900)]
ARM64: configs: add tizen_tw3_defconfig file

Add tizen_tw3_defconfig file.
This config is from Galileo Large Lte Na.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoscript: release.sh: remove the product specific codes
Jaehoon Chung [Mon, 3 Dec 2018 09:40:24 +0000 (18:40 +0900)]
script: release.sh: remove the product specific codes

Remove the product specific codes.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoRemove the unnecessary config files
Jaehoon Chung [Mon, 3 Dec 2018 09:28:47 +0000 (18:28 +0900)]
Remove the unnecessary config files

Remove the unnecessary config files.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoscripts: add the dtbtool and mkdzimage script files
Jaehoon Chung [Mon, 3 Dec 2018 03:47:33 +0000 (12:47 +0900)]
scripts: add the dtbtool and mkdzimage script files

Add the dtbtool and mkdzimage script files.
This file is from tw2 git repository.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
5 years agoImport codes from product
Jaehoon Chung [Fri, 30 Nov 2018 06:40:47 +0000 (15:40 +0900)]
Import codes from product

Impor codes from product.
These codes are from opensource.samsung.com.
- Version : R880XU1ARGB

6 years agoLinux 4.9.59 upstream v4.9.59
Greg Kroah-Hartman [Fri, 27 Oct 2017 08:38:11 +0000 (10:38 +0200)]
Linux 4.9.59

6 years agoFS-Cache: fix dereference of NULL user_key_payload
Eric Biggers [Mon, 9 Oct 2017 19:40:00 +0000 (12:40 -0700)]
FS-Cache: fix dereference of NULL user_key_payload

commit d124b2c53c7bee6569d2a2d0b18b4a1afde00134 upstream.

When the file /proc/fs/fscache/objects (available with
CONFIG_FSCACHE_OBJECT_LIST=y) is opened, we request a user key with
description "fscache:objlist", then access its payload.  However, a
revoked key has a NULL payload, and we failed to check for this.
request_key() *does* skip revoked keys, but there is still a window
where the key can be revoked before we access its payload.

Fix it by checking for a NULL payload, treating it like a key which was
already revoked at the time it was requested.

Fixes: 4fbf4291aa15 ("FS-Cache: Allow the current state of all objects to be dumped")
Reviewed-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoKEYS: Fix race between updating and finding a negative key
David Howells [Wed, 4 Oct 2017 15:43:25 +0000 (16:43 +0100)]
KEYS: Fix race between updating and finding a negative key

commit 363b02dab09b3226f3bd1420dad9c72b79a42a76 upstream.

Consolidate KEY_FLAG_INSTANTIATED, KEY_FLAG_NEGATIVE and the rejection
error into one field such that:

 (1) The instantiation state can be modified/read atomically.

 (2) The error can be accessed atomically with the state.

 (3) The error isn't stored unioned with the payload pointers.

This deals with the problem that the state is spread over three different
objects (two bits and a separate variable) and reading or updating them
atomically isn't practical, given that not only can uninstantiated keys
change into instantiated or rejected keys, but rejected keys can also turn
into instantiated keys - and someone accessing the key might not be using
any locking.

The main side effect of this problem is that what was held in the payload
may change, depending on the state.  For instance, you might observe the
key to be in the rejected state.  You then read the cached error, but if
the key semaphore wasn't locked, the key might've become instantiated
between the two reads - and you might now have something in hand that isn't
actually an error code.

The state is now KEY_IS_UNINSTANTIATED, KEY_IS_POSITIVE or a negative error
code if the key is negatively instantiated.  The key_is_instantiated()
function is replaced with key_is_positive() to avoid confusion as negative
keys are also 'instantiated'.

Additionally, barriering is included:

 (1) Order payload-set before state-set during instantiation.

 (2) Order state-read before payload-read when using the key.

Further separate barriering is necessary if RCU is being used to access the
payload content after reading the payload pointers.

Fixes: 146aa8b1453b ("KEYS: Merge the type-specific data with the payload data")
Reported-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agofscrypt: fix dereference of NULL user_key_payload
Eric Biggers [Mon, 9 Oct 2017 19:46:18 +0000 (12:46 -0700)]
fscrypt: fix dereference of NULL user_key_payload

commit d60b5b7854c3d135b869f74fb93eaf63cbb1991a upstream.

When an fscrypt-encrypted file is opened, we request the file's master
key from the keyrings service as a logon key, then access its payload.
However, a revoked key has a NULL payload, and we failed to check for
this.  request_key() *does* skip revoked keys, but there is still a
window where the key can be revoked before we acquire its semaphore.

Fix it by checking for a NULL payload, treating it like a key which was
already revoked at the time it was requested.

Fixes: 88bd6ccdcdd6 ("ext4 crypto: add encryption key management facilities")
Reviewed-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: trim writepage mapping to within eof
Brian Foster [Fri, 13 Oct 2017 16:47:46 +0000 (09:47 -0700)]
xfs: trim writepage mapping to within eof

commit 40214d128e07dd21bb07a8ed6a7fe2f911281ab2 upstream.

The writeback rework in commit fbcc02561359 ("xfs: Introduce
writeback context for writepages") introduced a subtle change in
behavior with regard to the block mapping used across the
->writepages() sequence. The previous xfs_cluster_write() code would
only flush pages up to EOF at the time of the writepage, thus
ensuring that any pages due to file-extending writes would be
handled on a separate cycle and with a new, updated block mapping.

The updated code establishes a block mapping in xfs_writepage_map()
that could extend beyond EOF if the file has post-eof preallocation.
Because we now use the generic writeback infrastructure and pass the
cached mapping to each writepage call, there is no implicit EOF
limit in place. If eofblocks trimming occurs during ->writepages(),
any post-eof portion of the cached mapping becomes invalid. The
eofblocks code has no means to serialize against writeback because
there are no pages associated with post-eof blocks. Therefore if an
eofblocks trim occurs and is followed by a file-extending buffered
write, not only has the mapping become invalid, but we could end up
writing a page to disk based on the invalid mapping.

Consider the following sequence of events:

- A buffered write creates a delalloc extent and post-eof
  speculative preallocation.
- Writeback starts and on the first writepage cycle, the delalloc
  extent is converted to real blocks (including the post-eof blocks)
  and the mapping is cached.
- The file is closed and xfs_release() trims post-eof blocks. The
  cached writeback mapping is now invalid.
- Another buffered write appends the file with a delalloc extent.
- The concurrent writeback cycle picks up the just written page
  because the writeback range end is LLONG_MAX. xfs_writepage_map()
  attributes it to the (now invalid) cached mapping and writes the
  data to an incorrect location on disk (and where the file offset is
  still backed by a delalloc extent).

This problem is reproduced by xfstests test generic/464, which
triggers racing writes, appends, open/closes and writeback requests.

To address this problem, trim the mapping used during writeback to
within EOF when the mapping is validated. This ensures the mapping
is revalidated for any pages encountered beyond EOF as of the time
the current mapping was cached or last validated.

Reported-by: Eryu Guan <eguan@redhat.com>
Diagnosed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: cancel dirty pages on invalidation
Dave Chinner [Fri, 13 Oct 2017 16:47:45 +0000 (09:47 -0700)]
xfs: cancel dirty pages on invalidation

commit 793d7dbe6d82a50b9d14bf992b9eaacb70a11ce6 upstream.

Recently we've had warnings arise from the vm handing us pages
without bufferheads attached to them. This should not ever occur
in XFS, but we don't defend against it properly if it does. The only
place where we remove bufferheads from a page is in
xfs_vm_releasepage(), but we can't tell the difference here between
"page is dirty so don't release" and "page is dirty but is being
invalidated so release it".

In some places that are invalidating pages ask for pages to be
released and follow up afterward calling ->releasepage by checking
whether the page was dirty and then aborting the invalidation. This
is a possible vector for releasing buffers from a page but then
leaving it in the mapping, so we really do need to avoid dirty pages
in xfs_vm_releasepage().

To differentiate between invalidated pages and normal pages, we need
to clear the page dirty flag when invalidating the pages. This can
be done through xfs_vm_invalidatepage(), and will result
xfs_vm_releasepage() seeing the page as clean which matches the
bufferhead state on the page after calling block_invalidatepage().

Hence we can re-add the page dirty check in xfs_vm_releasepage to
catch the case where we might be releasing a page that is actually
dirty and so should not have the bufferheads on it removed. This
will remove one possible vector of "dirty page with no bufferheads"
and so help narrow down the search for the root cause of that
problem.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: handle error if xfs_btree_get_bufs fails
Eric Sandeen [Tue, 10 Oct 2017 04:08:06 +0000 (21:08 -0700)]
xfs: handle error if xfs_btree_get_bufs fails

commit 93e8befc17f6d6ea92b0aee3741ceac8bca4590f upstream.

Jason reported that a corrupted filesystem failed to replay
the log with a metadata block out of bounds warning:

XFS (dm-2): _xfs_buf_find: Block out of range: block 0x80270fff8, EOFS 0x9c40000

_xfs_buf_find() and xfs_btree_get_bufs() return NULL if
that happens, and then when xfs_alloc_fix_freelist() calls
xfs_trans_binval() on that NULL bp, we oops with:

BUG: unable to handle kernel NULL pointer dereference at 00000000000000f8

We don't handle _xfs_buf_find errors very well, every
caller higher up the stack gets to guess at why it failed.
But we should at least handle it somehow, so return
EFSCORRUPTED here.

Reported-by: Jason L Tibbitts III <tibbs@math.uh.edu>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: reinit btree pointer on attr tree inactivation walk
Brian Foster [Mon, 9 Oct 2017 18:38:56 +0000 (11:38 -0700)]
xfs: reinit btree pointer on attr tree inactivation walk

commit f35c5e10c6ed6ba52a8dd8573924a80b6a02f03f upstream.

xfs_attr3_root_inactive() walks the attr fork tree to invalidate the
associated blocks. xfs_attr3_node_inactive() recursively descends
from internal blocks to leaf blocks, caching block address values
along the way to revisit parent blocks, locate the next entry and
descend down that branch of the tree.

The code that attempts to reread the parent block is unsafe because
it assumes that the local xfs_da_node_entry pointer remains valid
after an xfs_trans_brelse() and re-read of the parent buffer. Under
heavy memory pressure, it is possible that the buffer has been
reclaimed and reallocated by the time the parent block is reread.
This means that 'btree' can point to an invalid memory address, lead
to a random/garbage value for child_fsb and cause the subsequent
read of the attr fork to go off the rails and return a NULL buffer
for an attr fork offset that is most likely not allocated.

Note that this problem can be manufactured by setting
XFS_ATTR_BTREE_REF to 0 to prevent LRU caching of attr buffers,
creating a file with a multi-level attr fork and removing it to
trigger inactivation.

To address this problem, reinit the node/btree pointers to the
parent buffer after it has been re-read. This ensures btree points
to a valid record and allows the walk to proceed.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: don't change inode mode if ACL update fails
Dave Chinner [Mon, 9 Oct 2017 18:37:23 +0000 (11:37 -0700)]
xfs: don't change inode mode if ACL update fails

commit 67f2ffe31d1a683170c2ba0ecc643e42a5fdd397 upstream.

If we get ENOSPC half way through setting the ACL, the inode mode
can still be changed even though the ACL does not exist. Reorder the
operation to only change the mode of the inode if the ACL is set
correctly.

Whilst this does not fix the problem with crash consistency (that requires
attribute addition to be a deferred op) it does prevent ENOSPC and other
non-fatal errors setting an xattr to be handled sanely.

This fixes xfstests generic/449.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: move more RT specific code under CONFIG_XFS_RT
Dave Chinner [Mon, 9 Oct 2017 18:37:22 +0000 (11:37 -0700)]
xfs: move more RT specific code under CONFIG_XFS_RT

commit bb9c2e5433250f5b477035dc478314f8e6dd5e36 upstream.

Various utility functions and interfaces that iterate internal
devices try to reference the realtime device even when RT support is
not compiled into the kernel.

Make sure this code is excluded from the CONFIG_XFS_RT=n build,
and where appropriate stub functions to return fatal errors if
they ever get called when RT support is not present.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: Don't log uninitialised fields in inode structures
Dave Chinner [Mon, 9 Oct 2017 18:37:22 +0000 (11:37 -0700)]
xfs: Don't log uninitialised fields in inode structures

commit 20413e37d71befd02b5846acdaf5e2564dd1c38e upstream.

Prevent kmemcheck from throwing warnings about reading uninitialised
memory when formatting inodes into the incore log buffer. There are
several issues here - we don't always log all the fields in the
inode log format item, and we never log the inode the
di_next_unlinked field.

In the case of the inode log format item, this is exacerbated
by the old xfs_inode_log_format structure padding issue. Hence make
the padded, 64 bit aligned version of the structure the one we always
use for formatting the log and get rid of the 64 bit variant. This
means we'll always log the 64-bit version and so recovery only needs
to convert from the unpadded 32 bit version from older 32 bit
kernels.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: handle racy AIO in xfs_reflink_end_cow
Christoph Hellwig [Tue, 3 Oct 2017 15:58:33 +0000 (08:58 -0700)]
xfs: handle racy AIO in xfs_reflink_end_cow

commit e12199f85d0ad1b04ce6c425ad93cd847fe930bb upstream.

If we got two AIO writes into a COW area the second one might not have any
COW extents left to convert.  Handle that case gracefully instead of
triggering an assert or accessing beyond the bounds of the extent list.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: always swap the cow forks when swapping extents
Darrick J. Wong [Mon, 18 Sep 2017 16:41:18 +0000 (09:41 -0700)]
xfs: always swap the cow forks when swapping extents

commit 52bfcdd7adbc26639bc7b2356ab9a3f5dad68ad6 upstream.

Since the CoW fork exists as a secondary data structure to the data
fork, we must always swap cow forks during swapext.  We also need to
swap the extent counts and reset the cowblocks tags.

Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 years agoxfs: Capture state of the right inode in xfs_iflush_done
Carlos Maiolino [Fri, 22 Sep 2017 18:47:46 +0000 (11:47 -0700)]
xfs: Capture state of the right inode in xfs_iflush_done

commit 842f6e9f786226c58fcbd5ef80eadca72fdfe652 upstream.

My previous patch: d3a304b6292168b83b45d624784f973fdc1ca674 check for
XFS_LI_FAILED flag xfs_iflush done, so the failed item can be properly
resubmitted.

In the loop scanning other inodes being completed, it should check the
current item for the XFS_LI_FAILED, and not the initial one.

The state of the initial inode is checked after the loop ends

Kudos to Eric for catching this.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>