From c1704daac27e340866215677eee00fd28f6b77b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 28 Jan 2021 17:31:15 +0100 Subject: [PATCH 01/16] kdbus: Use sizeof_field() macro MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Replace of FIELD_SIZEOF() with sizeof_field(). Change-Id: I6647be8fa77ca24bfa3b8d1ed57e8fc6a5a4c98a Fixes: c593642c8be0 ("treewide: Use sizeof_field() macro") Signed-off-by: Łukasz Stelmach --- ipc/kdbus/util.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipc/kdbus/util.h b/ipc/kdbus/util.h index cf1403b..38c2ed5 100644 --- a/ipc/kdbus/util.h +++ b/ipc/kdbus/util.h @@ -17,6 +17,7 @@ #include #include +#include #include @@ -40,7 +41,7 @@ ({ \ u64 __user *_sz = \ (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \ - copy_to_user(_sz, _s, FIELD_SIZEOF(_t, _m)); \ + copy_to_user(_sz, _s, sizeof_field(_t, _m)); \ }) /** -- 2.7.4 From 7889ec311fae9c9f2e9a37e4f8af70599bccbf4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Tue, 2 Feb 2021 19:52:58 +0100 Subject: [PATCH 02/16] pid: mark struct pid* argument as const MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I17a358ccbae656561e9e1df4ff3fe0055e4eaf20 Signed-off-by: Łukasz Stelmach --- include/linux/pid.h | 4 ++-- kernel/pid.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index fa10acb..a19f612 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -87,12 +87,12 @@ static inline struct pid *get_pid(struct pid *pid) } extern void put_pid(struct pid *pid); -extern struct task_struct *pid_task(struct pid *pid, enum pid_type); +extern struct task_struct *pid_task(const struct pid *pid, enum pid_type); static inline bool pid_has_task(struct pid *pid, enum pid_type type) { return !hlist_empty(&pid->tasks[type]); } -extern struct task_struct *get_pid_task(struct pid *pid, enum pid_type); +extern struct task_struct *get_pid_task(const struct pid *pid, enum pid_type); extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type); diff --git a/kernel/pid.c b/kernel/pid.c index 4856818..3e510e6 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -393,7 +393,7 @@ void transfer_pid(struct task_struct *old, struct task_struct *new, hlist_replace_rcu(&old->pid_links[type], &new->pid_links[type]); } -struct task_struct *pid_task(struct pid *pid, enum pid_type type) +struct task_struct *pid_task(const struct pid *pid, enum pid_type type) { struct task_struct *result = NULL; if (pid) { @@ -445,7 +445,7 @@ struct pid *get_task_pid(struct task_struct *task, enum pid_type type) } EXPORT_SYMBOL_GPL(get_task_pid); -struct task_struct *get_pid_task(struct pid *pid, enum pid_type type) +struct task_struct *get_pid_task(const struct pid *pid, enum pid_type type) { struct task_struct *result; rcu_read_lock(); -- 2.7.4 From c86613173f35324bf77ed6f51ed02ba0cde3753d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 4 Feb 2021 15:35:27 +0100 Subject: [PATCH 03/16] kdbus: read hide_pid and pid_gid from mounted proc MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since commit fa10fed30f25 ("proc: allow to mount many instances of proc in one pid namespace") there may be more than one instance of procfs mounted in a single namespace. Each instance can have different hide_pid and pid_gid parameters. The highest value of hide_pid (most restrictive) of all mounted procfs instances is used to check permissions. Change-Id: Ifc8db04eaa3e21973bc647e1e7768a561f40db99 Fixes: fa10fed30f25 ("proc: allow to mount many instances of proc in one pid namespace") Signed-off-by: Łukasz Stelmach --- ipc/kdbus/metadata.c | 71 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c index 2f93d602..bdf8253 100644 --- a/ipc/kdbus/metadata.c +++ b/ipc/kdbus/metadata.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -1163,28 +1165,68 @@ enum { KDBUS_META_PROC_NORMAL, }; +static int max_hide_pid(struct vfsmount *mnt, void *arg) +{ + struct proc_fs_info *fs_info_out = arg; + struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; + struct super_block *sb = mnt_path.dentry->d_sb; + struct proc_fs_info *fs_info_in = sb->s_fs_info; + + if (strcmp("proc", sb->s_type->name) != 0) + return 0; + + if (fs_info_out->hide_pid <= fs_info_in->hide_pid) { + fs_info_out->hide_pid = fs_info_in->hide_pid; + fs_info_out->pid_gid = fs_info_in->pid_gid; + } + + return 0; +} + /** * kdbus_proc_permission() - check /proc permissions on target pid - * @pid_ns: namespace we operate in - * @cred: credentials of requestor + * @req_pid: pid of requestor + * @req_cred: credentials of requestor * @target: target process * - * This checks whether a process with credentials @cred can access information - * of @target in the namespace @pid_ns. This tries to follow /proc permissions, - * but is slightly more restrictive. + * This checks whether a process with credentials @cred can access + * information of @target in the namespace of @req_pid. This tries to + * follow /proc permissions, but is slightly more restrictive. * * Return: The /proc access level (KDBUS_META_PROC_*) is returned. */ -static unsigned int kdbus_proc_permission(const struct pid_namespace *pid_ns, - const struct cred *cred, +static unsigned int kdbus_proc_permission(const struct pid *req_pid, + const struct cred *req_cred, struct pid *target) { - if (pid_ns->hide_pid < 1) - return KDBUS_META_PROC_NORMAL; + struct task_struct *task = get_pid_task(req_pid, PIDTYPE_PID); + struct vfsmount *root_mnt; + struct path path; + unsigned int ret = KDBUS_META_PROC_NONE; + struct proc_fs_info fs_info; + + if (!task) + return ret; + + fs_info.hide_pid = 0; + + get_fs_root(task->fs, &path); + root_mnt = collect_mounts(&path); + path_put(&path); + + ret = PTR_ERR(root_mnt); + if (IS_ERR(root_mnt)) + goto out; + + iterate_mounts(max_hide_pid, &fs_info, root_mnt); + + ret = KDBUS_META_PROC_NORMAL; + if (fs_info.hide_pid < 1) + goto out; /* XXX: we need groups_search() exported for aux-groups */ - if (gid_eq(cred->egid, pid_ns->pid_gid)) - return KDBUS_META_PROC_NORMAL; + if (gid_eq(req_cred->egid, fs_info.pid_gid)) + goto out; /* * XXX: If ptrace_may_access(PTRACE_MODE_READ) is granted, you can @@ -1193,7 +1235,10 @@ static unsigned int kdbus_proc_permission(const struct pid_namespace *pid_ns, * simply decide to not support this override, so no need to worry. */ - return KDBUS_META_PROC_NONE; + ret = KDBUS_META_PROC_NONE; +out: + put_task_struct(task); + return ret; } /** @@ -1237,7 +1282,7 @@ static u64 kdbus_meta_proc_mask(struct pid *prv_pid, if (prv_pid == req_pid) proc = KDBUS_META_PROC_NORMAL; else - proc = kdbus_proc_permission(req_ns, req_cred, prv_pid); + proc = kdbus_proc_permission(req_pid, req_cred, prv_pid); /* you need /proc access to read standard process attributes */ if (proc < KDBUS_META_PROC_NORMAL) -- 2.7.4 From 9b6eec61ca4f68bbdc6c40ad7ca4e67bed320556 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Fri, 22 Jan 2021 12:40:18 +0900 Subject: [PATCH 04/16] usb: gadget: f_fs: Fix use-after-free for unbind with remaining io If usb has stall, then there can be remaining submitted io and unbinding f_fs with the remaining io, there is use-after-free. Fix the use-after-free by checking endpoint after wait. This fixes following kasan warning: BUG: KASAN: use-after-free in ffs_epfile_io+0x654/0xb58 Read of size 4 at addr ffffffc0a44e65dc by task mtp-responder/5117 ... [] ffs_epfile_io+0x654/0xb58 [] ffs_epfile_read_iter+0x1ac/0x3e0 ... Allocated by task 3869: ... __kmalloc+0x234/0x760 _ffs_func_bind+0x264/0x7c8 ffs_func_bind+0xe8/0x650 usb_add_function+0x13c/0x378 ... Freed by task 3869: ... kfree+0xa4/0x750 ffs_func_unbind+0x150/0x248 purge_configs_funcs+0x1a0/0x310 ... Signed-off-by: Seung-Woo Kim [dwoo08.lee: cherry-picked from linux-amlogic commit 5dd3ffecd46f to prevent use-after-free when f_fs is unbound before all requests are over] Signed-off-by: Dongwoo Lee Change-Id: Idf2391c53ca0f90fc9484d725304b88fc57fa8a6 --- drivers/usb/gadget/function/f_fs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index cdc45bd..1a05d1f 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1097,7 +1097,8 @@ retry_malloc: spin_unlock_irq(&epfile->ffs->eps_lock); - if (unlikely(wait_for_completion_interruptible(&done))) { + if (unlikely(wait_for_completion_interruptible(&done)) && + epfile->ep) { /* * To avoid race condition with ffs_epfile_io_complete, * dequeue the request first then check @@ -1109,6 +1110,12 @@ retry_malloc: interrupted = ep->status < 0; } + if (epfile->ep != ep) { + /* In the meantime, endpoint got disabled or changed. */ + ret = -ESHUTDOWN; + goto error_mutex; + } + if (interrupted) ret = -EINTR; else if (io_data->read && ep->status > 0) -- 2.7.4 From a53cad5f3535c94773a9faae4aaa5596c0de7b04 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Mon, 25 Jan 2021 16:24:03 +0900 Subject: [PATCH 05/16] ARM64: tizen_bcm2711_defconfig: Enable OVERLAY_FS Enable CONFIG_OVERLAY_FS for tizen application space. Change-Id: I1b2aafaeea24b6ef6b07d3c57d542dce13c53b8f Signed-off-by: Seung-Woo Kim --- arch/arm64/configs/tizen_bcm2711_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 79d8a8e..3e07c68 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -415,6 +415,7 @@ CONFIG_F2FS_FS=y CONFIG_FANOTIFY=y CONFIG_AUTOFS4_FS=y CONFIG_FUSE_FS=y +CONFIG_OVERLAY_FS=y CONFIG_FSCACHE=y CONFIG_FSCACHE_STATS=y CONFIG_FSCACHE_HISTOGRAM=y -- 2.7.4 From 7d5ab8d046419990f5affc8324f1d5eb76fb218d Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Mon, 25 Jan 2021 16:24:54 +0900 Subject: [PATCH 06/16] ARM: tizen_bcm2711_defconfig: Enable OVERLAY_FS Enable CONFIG_OVERLAY_FS for tizen application space. Change-Id: I46b011effa26e1f7ef9acf5f18d52bc7b54452c5 Signed-off-by: Seung-Woo Kim --- arch/arm/configs/tizen_bcm2711_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index b972791..d3b89a0 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -428,6 +428,7 @@ CONFIG_F2FS_FS=y CONFIG_FANOTIFY=y CONFIG_AUTOFS4_FS=y CONFIG_FUSE_FS=y +CONFIG_OVERLAY_FS=y CONFIG_FSCACHE=y CONFIG_FSCACHE_STATS=y CONFIG_FSCACHE_HISTOGRAM=y -- 2.7.4 From 4af4d13d4df364bfdf946ba4422e5ab858611eed Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Wed, 17 Feb 2021 10:02:48 +0900 Subject: [PATCH 07/16] ARM/ARM64: defconfig: disable SECURITY_SMACK_NETFILTER config Disable SECURITY_SMACK_NETFILTER configuration. Change-Id: Id95847392ac2bf53b92dae5ee2c0d4b5c1e41ece Signed-off-by: Jaehoon Chung --- arch/arm/configs/tizen_bcm2711_defconfig | 1 - arch/arm64/configs/tizen_bcm2711_defconfig | 1 - 2 files changed, 2 deletions(-) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index d3b89a0..40dd1b4 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -458,7 +458,6 @@ CONFIG_NLS_ASCII=y CONFIG_NLS_ISO8859_1=y CONFIG_SECURITY=y CONFIG_SECURITY_SMACK=y -CONFIG_SECURITY_SMACK_NETFILTER=y CONFIG_SECURITY_SMACK_APPEND_SIGNALS=y # CONFIG_INTEGRITY is not set CONFIG_CRYPTO_XTS=y diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 3e07c68..26421cc 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -436,7 +436,6 @@ CONFIG_NLS_ASCII=y CONFIG_NLS_ISO8859_1=y CONFIG_SECURITY=y CONFIG_SECURITY_SMACK=y -CONFIG_SECURITY_SMACK_NETFILTER=y CONFIG_SECURITY_SMACK_APPEND_SIGNALS=y # CONFIG_INTEGRITY is not set CONFIG_CRYPTO_USER=y -- 2.7.4 From 3ac2ae5376f37d2c125e5eb876381f392a708a2e Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Thu, 25 Feb 2021 17:17:12 +0900 Subject: [PATCH 08/16] media: uvcvideo: Add a probe quirk to Jieli Technology USB PHY 2.0 (1224:2a25) Repeated video request on Jieli Technology USB PHY 2.0 (1224:2a25) device causes data stall with below error until reconnection: uvcvideo: Failed to set UVC probe control : -32 (exp. 26). To resolve the wrong state, add PROBE quirk bits. Change-Id: I5efba6ac26d5eea70e2227f9ff9801dd5d8d4790 Signed-off-by: Seung-Woo Kim --- drivers/media/usb/uvc/uvc_driver.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 5ad5282..4082a42 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2972,6 +2972,16 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, + /* Jieli Technology USB PHY 2.0 / QSENN webcam */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x1224, + .idProduct = 0x2a25, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX + | UVC_QUIRK_PROBE_EXTRAFIELDS) }, /* Generic USB Video Class */ { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) }, { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) }, -- 2.7.4 From 3d4f6677e22e5b619dfe8b988421e250333c9f67 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Mon, 22 Mar 2021 16:56:08 +0900 Subject: [PATCH 09/16] Revert "ARM: configs: tizen_bcm2711_defconfig: Disable CONFIG_CFG80211_CRDA_SUPPORT" This reverts commit 6485924bd76b70c8ed6ba334ef9b5045f4a3686d. - Enable CONFIG_CFG80211_CRDA_SUPPORT to use country code. Change-Id: I951b32c86611b6240991e9bb8b362c98bb56b72c Signed-off-by: Jaehoon Chung --- arch/arm/configs/tizen_bcm2711_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index 40dd1b4..6e15072 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -193,7 +193,6 @@ CONFIG_BT_HCIUART=y CONFIG_BT_HCIUART_BCM=y CONFIG_BT_HCIBCM203X=m CONFIG_CFG80211=y -# CONFIG_CFG80211_CRDA_SUPPORT is not set CONFIG_CFG80211_WEXT=y CONFIG_MAC80211=y CONFIG_MAC80211_MESH=y -- 2.7.4 From eef82731195960c36900ac026826cf19b9b9df5d Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Mon, 22 Mar 2021 17:06:33 +0900 Subject: [PATCH 10/16] ARM64: tizen_bcm2711_defconfig: Enable CONFIG_CFG80211_CRDA_SUPPORT Enable CONFIG_CFG80211_CRDA_SUPPORT. Change-Id: If60cab97a05ca8bc01633255ede56279fcc599a8 Signed-off-by: Jaehoon Chung --- arch/arm64/configs/tizen_bcm2711_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 26421cc..b53d3e3 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -192,7 +192,6 @@ CONFIG_BT_HCIUART=y CONFIG_BT_HCIUART_BCM=y CONFIG_BT_HCIBCM203X=m CONFIG_CFG80211=y -# CONFIG_CFG80211_CRDA_SUPPORT is not set CONFIG_CFG80211_WEXT=y CONFIG_MAC80211=y CONFIG_MAC80211_MESH=y -- 2.7.4 From 79912bbbff1e5e841fa4c5bb698fc9dac27e4ec8 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 24 Mar 2021 12:44:24 +0900 Subject: [PATCH 11/16] ARM: tizen_bcm2711_defconfig: Enable USB_PRINTER config Enable USB_PRINTER config to suppot USB printer device. Change-Id: Ic63797d93520e4bc50175c53c7e7328b55a0f724 Signed-off-by: Chanwoo Choi --- arch/arm/configs/tizen_bcm2711_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index 6e15072..d289dcc 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -357,6 +357,7 @@ CONFIG_USB_ANNOUNCE_NEW_DEVICES=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_ACM=m +CONFIG_USB_PRINTER=y CONFIG_USB_STORAGE=y CONFIG_USB_UAS=y CONFIG_USB_DWC2=y -- 2.7.4 From 16e7ccc97cea65fe98f25d008d0425563f93806c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 24 Mar 2021 12:45:52 +0900 Subject: [PATCH 12/16] ARM64: tizen_bcm2711_defconfig: Enable USB_PRINTER config Enable USB_PRINTER config to suppot USB printer device. Change-Id: I2068a283928c8f3c85d5f31b25a13300cdc52783 Signed-off-by: Chanwoo Choi --- arch/arm64/configs/tizen_bcm2711_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index b53d3e3..2cdf050 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -346,6 +346,7 @@ CONFIG_USB_ANNOUNCE_NEW_DEVICES=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_ACM=m +CONFIG_USB_PRINTER=y CONFIG_USB_STORAGE=y CONFIG_USB_UAS=y CONFIG_USB_DWC2=y -- 2.7.4 From 231582f4b460b8a94ea77a93f58a450f1d9e114f Mon Sep 17 00:00:00 2001 From: Hoegeun Kwon Date: Tue, 30 Mar 2021 11:04:39 +0900 Subject: [PATCH 13/16] packaging: Change the kernel version of the spec file Change the kernel version to 5.10.25 Change-Id: Ibe698990fefa9e336212788089d7e2503726da88 Signed-off-by: Hoegeun Kwon --- packaging/linux-rpi4.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/linux-rpi4.spec b/packaging/linux-rpi4.spec index 9bb4c15..8a42ec1 100644 --- a/packaging/linux-rpi4.spec +++ b/packaging/linux-rpi4.spec @@ -12,7 +12,7 @@ Name: rpi4-linux-kernel Summary: The Linux Kernel for Raspberry Pi4 -Version: 5.4.50 +Version: 5.10.25 Release: 0 License: GPL-2.0 ExclusiveArch: %{arm} aarch64 -- 2.7.4 From 411b0d1264699f41a9877d7c219efd7167c5e07a Mon Sep 17 00:00:00 2001 From: Hoegeun Kwon Date: Thu, 1 Apr 2021 14:25:00 +0900 Subject: [PATCH 14/16] ARM: tizen_bcm2711_defconfig: Enable ARM_MODULE_PLTS config Fixes the problem of not loading kernel modules Change-Id: I3eeed53c510610b69e2ab8b6ddc09a5680fb54c9 Signed-off-by: Hoegeun Kwon Signed-off-by: Seung-Woo Kim --- arch/arm/configs/tizen_bcm2711_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index d289dcc..cdd87318 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -34,7 +34,6 @@ CONFIG_ARM_LPAE=y # CONFIG_CACHE_L2X0 is not set CONFIG_SMP=y CONFIG_HIGHMEM=y -# CONFIG_ARM_MODULE_PLTS is not set CONFIG_UACCESS_WITH_MEMCPY=y # CONFIG_ATAGS is not set CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" -- 2.7.4 From db906a57d2688f51243967da3bb69da506c4808e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Fri, 12 Feb 2021 18:41:09 +0100 Subject: [PATCH 15/16] logger: accept untagged log entries MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add support for writing untagged log messages to /dev/log_* nodes. The logger shall accept untagget messages after setting the tag and the priority with appropriate ioctl() commands for particular file descriptors. Change-Id: I02bd7bfd843eaf316692413a48747009c42756f6 Signed-off-by: Łukasz Stelmach --- drivers/staging/android/logger.c | 364 +++++++++++++++++++++++++++++++++++---- drivers/staging/android/logger.h | 2 + 2 files changed, 331 insertions(+), 35 deletions(-) diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c index 405160c..fb1c952 100644 --- a/drivers/staging/android/logger.c +++ b/drivers/staging/android/logger.c @@ -29,9 +29,10 @@ #include #include #include -#include "logger.h" +#include +#include -#include +#include "logger.h" /** * struct logger_log - represents a specific log, such as 'main' or 'radio' @@ -64,6 +65,27 @@ struct logger_log { static LIST_HEAD(log_list); /** + * struct log_writer - a logging device open for writing + * @log: The associated log + * @list: The associated entry in @logger_log's list + * @b_off: The current position in @buf + * @tag: A tag to be attached to messages + * @prio: Default message priority value + * @buff: Temporary space to assemble messages. + */ +struct logger_writer { + struct logger_log *log; + struct task_struct *owner; + struct task_struct *b_owner; + struct logger_entry b_header; + size_t b_off; + size_t tag_len; + char *tag; + int prio; + char *buffer; +}; + +/** * struct logger_reader - a logging device open for reading * @log: The associated log * @list: The associated entry in @logger_log's list @@ -104,12 +126,15 @@ static size_t logger_offset(struct logger_log *log, size_t n) */ static inline struct logger_log *file_get_log(struct file *file) { + struct logger_writer *writer = file->private_data; + if (file->f_mode & FMODE_READ) { struct logger_reader *reader = file->private_data; return reader->log; } - return file->private_data; + + return writer->log; } /* @@ -409,6 +434,125 @@ static void fix_up_readers(struct logger_log *log, size_t len) reader->r_off = get_next_entry(log, reader->r_off, len); } +static char *strnrchr(const char *s, size_t count, int c) +{ + const char *last = NULL; + if (!count) + return NULL; + do { + if (*s == (char)c) + last = s; + } while (--count && *s++); + return (char *)last; +} + +static struct file *replace_file(struct files_struct *files, + struct file *oldf, + struct file *newf) +{ + struct file *file = NULL; + struct fdtable *fdt; + unsigned int i; + + spin_lock(&files->file_lock); + fdt = files_fdtable(files); + for (i = 0; i < fdt->max_fds && file != oldf; i++) { + if (fdt->fd[i] == oldf) { + file = xchg(&fdt->fd[i], newf); + } + } + spin_unlock(&files->file_lock); + + if (file) + filp_close(file, files); + + return file; +} + +static struct file *make_new_file(struct file *file) +{ + struct logger_writer *writer = file->private_data; + struct logger_writer *nwriter; + struct file *nfile; + char *pbuf, *p; + + pbuf = kzalloc(PATH_MAX, GFP_KERNEL); + if (!pbuf) { + return ERR_PTR(-ENOMEM); + } + + p = file_path(file, pbuf, PATH_MAX); + if (!p) { + kfree(pbuf); + return ERR_PTR(-EFAULT); + } + + nfile = filp_open(p, O_WRONLY, 0); + kfree(pbuf); + if (!nfile) { + return ERR_PTR(-EFAULT); + } + + nwriter = nfile->private_data; + nwriter->prio = writer->prio; + nwriter->tag = kstrdup(writer->tag, GFP_KERNEL); + nwriter->tag_len = writer->tag_len; + + if (!replace_file(current->files, file, nfile)) { + filp_close(nfile, current->files); + return ERR_PTR(-EFAULT); + } + + return nfile; +} + +static void write_log_data(struct logger_log *log, + struct logger_entry *header, + struct logger_writer *writer, + size_t chunk_len) +{ + size_t len, w_off; + + /* header */ + len = min(sizeof(struct logger_entry), log->size - log->w_off); + memcpy(log->buffer + log->w_off, header, len); + memcpy(log->buffer, (char *)header + len, sizeof(struct logger_entry) - len); + w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry)); + + /* priority */ + log->buffer[w_off] = (unsigned char)writer->prio; + w_off = logger_offset(log, w_off + 1); + + /* tag */ + len = min_t(size_t, writer->tag_len + 1, log->size - w_off); + memcpy(log->buffer + w_off, writer->tag, len); + memcpy(log->buffer, writer->tag + len, writer->tag_len + 1 - len); + w_off = logger_offset(log, w_off + writer->tag_len + 1); + + /* message */ + len = min(chunk_len, log->size - w_off); + memcpy(log->buffer + w_off, writer->buffer, chunk_len); + memcpy(log->buffer, writer->buffer + len, chunk_len - len); + log->w_off = logger_offset(log, w_off + chunk_len); +} + +static void flush_thread_data(struct file* file) +{ + struct logger_writer *writer = file->private_data; + struct logger_log *log = file_get_log(file); + size_t len, w_off, chunk_len = 0; + + chunk_len = writer->b_off + 1; + writer->b_header.len = chunk_len + writer->tag_len + 2; + + fix_up_readers(log, sizeof(struct logger_entry) + writer->b_header.len); + + write_log_data(log, &writer->b_header, writer, chunk_len); + + writer->b_off = 0; + writer->buffer[0] = '\0'; +} + /* * logger_write_iter - our write method, implementing support for write(), * writev(), and aio_write(). Writes are our fast path, and we try to optimize @@ -416,10 +560,16 @@ static void fix_up_readers(struct logger_log *log, size_t len) */ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) { - struct logger_log *log = file_get_log(iocb->ki_filp); + struct file *file = iocb->ki_filp; + struct logger_writer *writer = file->private_data; + struct logger_log *log = file_get_log(file); struct logger_entry header; struct timespec64 now; size_t len, count, w_off; + bool from_stdio = false; + + if (writer->tag && writer->prio >= 2) + from_stdio = true; count = min_t(size_t, iov_iter_count(from), LOGGER_ENTRY_MAX_PAYLOAD); @@ -439,46 +589,120 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) mutex_lock(&log->mutex); - /* - * Fix up any readers, pulling them forward to the first readable - * entry after (what will be) the new write offset. We do this now - * because if we partially fail, we can end up with clobbered log - * entries that encroach on readable buffer. - */ - fix_up_readers(log, sizeof(struct logger_entry) + header.len); + /* Prepend messages from STDOUT and STDERR with a tag and prio */ + if (from_stdio) { + char *p; + size_t chunk_len = 0; + size_t max_payload = LOGGER_ENTRY_MAX_PAYLOAD - writer->tag_len - 2; - len = min(sizeof(header), log->size - log->w_off); - memcpy(log->buffer + log->w_off, &header, len); - memcpy(log->buffer, (char *)&header + len, sizeof(header) - len); + if (writer->owner != current->group_leader) { + struct file *nfile; - /* Work with a copy until we are ready to commit the whole entry */ - w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry)); + nfile = make_new_file(file); + if (IS_ERR(nfile)) { + mutex_unlock(&log->mutex); + return PTR_ERR(nfile); + } + + file = nfile; + writer = file->private_data; + } + + /* Allocate STDIO line buffer */ + if (!writer->buffer) { + writer->buffer = kzalloc(LOGGER_ENTRY_MAX_PAYLOAD, GFP_KERNEL); + writer->b_off = 0; + + if (!writer->buffer) { + mutex_unlock(&log->mutex); + return -ENOMEM; + } + } + + /* flush message from a different thread */ + if (writer->b_owner != current && writer->b_off) + flush_thread_data(file); + + count = min_t(size_t, iov_iter_count(from), max_payload - 1); + + do { + + if (copy_from_iter(writer->buffer + writer->b_off, count, from) != count) { + mutex_unlock(&log->mutex); + return -EFAULT; + } - len = min(count, log->size - w_off); + /* TODO: replace NULL characters with new lines */ + p = strnrchr(writer->buffer + writer->b_off, count, '\n'); + if (p) { + *p++ = '\0'; + chunk_len = p - writer->buffer; + } else { + writer->buffer[count++] = '\0'; + chunk_len = count; + } + + header.len = chunk_len + writer->tag_len + 2; + fix_up_readers(log, sizeof(struct logger_entry) + header.len); + + write_log_data(log, &header, writer, chunk_len); + + /* move the remaining part of the message */ + memmove(writer->buffer, p, writer->b_off + count - chunk_len); + + /* new b_off points where the rimainder of the string ends */ + writer->b_off = writer->b_off + count - chunk_len; + writer->buffer[writer->b_off] = '\0'; + + } while ((count = min_t(size_t, iov_iter_count(from), max_payload - 1))); + + /* save for remaining unfinished line */ + writer->b_header = header; + writer->b_owner = current; + } else { - if (copy_from_iter(log->buffer + w_off, len, from) != len) { /* - * Note that by not updating log->w_off, this abandons the - * portion of the new entry that *was* successfully - * copied, just above. This is intentional to avoid - * message corruption from missing fragments. + * Fix up any readers, pulling them forward to the first readable + * entry after (what will be) the new write offset. We do this now + * because if we partially fail, we can end up with clobbered log + * entries that encroach on readable buffer. */ - mutex_unlock(&log->mutex); - return -EFAULT; - } + fix_up_readers(log, sizeof(struct logger_entry) + header.len); - if (copy_from_iter(log->buffer, count - len, from) != count - len) { - mutex_unlock(&log->mutex); - return -EFAULT; + len = min(sizeof(header), log->size - log->w_off); + memcpy(log->buffer + log->w_off, &header, len); + memcpy(log->buffer, (char *)&header + len, sizeof(header) - len); + + /* Work with a copy until we are ready to commit the whole entry */ + w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry)); + + len = min(count, log->size - w_off); + + if (copy_from_iter(log->buffer + w_off, len, from) != len) { + /* + * Note that by not updating log->w_off, this abandons the + * portion of the new entry that *was* successfully + * copied, just above. This is intentional to avoid + * message corruption from missing fragments. + */ + mutex_unlock(&log->mutex); + return -EFAULT; + } + + if (copy_from_iter(log->buffer, count - len, from) != count - len) { + mutex_unlock(&log->mutex); + return -EFAULT; + } + + log->w_off = logger_offset(log, w_off + count); } - log->w_off = logger_offset(log, w_off + count); mutex_unlock(&log->mutex); /* wake up any blocked readers */ wake_up_interruptible(&log->wq); - return len; + return count; } static struct logger_log *get_log_from_minor(int minor) @@ -530,7 +754,16 @@ static int logger_open(struct inode *inode, struct file *file) file->private_data = reader; } else { - file->private_data = log; + struct logger_writer *writer; + + writer = kzalloc(sizeof(struct logger_writer), GFP_KERNEL); + if (!writer) + return -ENOMEM; + + writer->log = log; + writer->owner = current->group_leader; + + file->private_data = writer; } return 0; @@ -552,6 +785,12 @@ static int logger_release(struct inode *ignored, struct file *file) mutex_unlock(&log->mutex); kfree(reader); + } else { + struct logger_writer *writer = file->private_data; + + kfree(writer->tag); + kfree(writer->buffer); + kfree(writer); } return 0; @@ -606,10 +845,53 @@ static long logger_set_version(struct logger_reader *reader, void __user *arg) return 0; } +static long logger_set_prio(struct logger_writer *writer, void __user *arg) +{ + int prio; + + prio = (int)arg; + + if ((prio < 2) || (prio > 7)) + return -EINVAL; + + writer->prio = prio; + return 0; +} + +static long logger_set_tag(struct logger_writer *writer, void __user *arg) +{ + int len; + char *p, *q; + + if (copy_from_user(&len, arg, sizeof(int))) + return -EFAULT; + + arg += sizeof(int); + + + p = kzalloc(len, GFP_KERNEL); + if (!p) + return -ENOMEM; + + if (copy_from_user(p, arg, len)) { + kfree(p); + return -EFAULT; + } + p[len-1] = '\0'; + + q = writer->tag; + writer->tag = p; + writer->tag_len = len - 1; /* without NULL */ + kfree(q); + + return 0; +} + static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct logger_log *log = file_get_log(file); struct logger_reader *reader; + struct logger_writer *writer; long ret = -EINVAL; void __user *argp = (void __user *)arg; @@ -648,10 +930,6 @@ static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ret = 0; break; case LOGGER_FLUSH_LOG: - if (!(file->f_mode & FMODE_WRITE)) { - ret = -EBADF; - break; - } if (!(in_egroup_p(file_inode(file)->i_gid) || capable(CAP_SYSLOG))) { ret = -EPERM; @@ -678,6 +956,22 @@ static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg) reader = file->private_data; ret = logger_set_version(reader, argp); break; + case LOGGER_SET_PRIO: /* 44552 */ + if (file->f_mode & FMODE_READ) { + ret = -EBADF; + break; + } + writer = file->private_data; + ret = logger_set_prio(writer, argp); + break; + case LOGGER_SET_TAG: /* 44551 */ + if (file->f_mode & FMODE_READ) { + ret = -EBADF; + break; + } + writer = file->private_data; + ret = logger_set_tag(writer, argp); + break; } mutex_unlock(&log->mutex); diff --git a/drivers/staging/android/logger.h b/drivers/staging/android/logger.h index 70af7d8..b11e48c 100644 --- a/drivers/staging/android/logger.h +++ b/drivers/staging/android/logger.h @@ -85,5 +85,7 @@ struct logger_entry { #define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) /* flush log */ #define LOGGER_GET_VERSION _IO(__LOGGERIO, 5) /* abi version */ #define LOGGER_SET_VERSION _IO(__LOGGERIO, 6) /* abi version */ +#define LOGGER_SET_TAG _IO(__LOGGERIO, 7) /* stdio tag */ +#define LOGGER_SET_PRIO _IO(__LOGGERIO, 8) /* stdio priority */ #endif /* _LINUX_LOGGER_H */ -- 2.7.4 From 2de0459eef2e35a4b31be79b03f31161b564802c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Mon, 15 Feb 2021 15:41:27 +0100 Subject: [PATCH 16/16] logger: testing tool for STDIO logger MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I029a7def836b317a4e059c7a56301e169910a830 Signed-off-by: Łukasz Stelmach --- tools/testing/selftests/logger/.gitignore | 1 + tools/testing/selftests/logger/Makefile | 24 +++++ tools/testing/selftests/logger/logger.c | 155 ++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 tools/testing/selftests/logger/.gitignore create mode 100644 tools/testing/selftests/logger/Makefile create mode 100644 tools/testing/selftests/logger/logger.c diff --git a/tools/testing/selftests/logger/.gitignore b/tools/testing/selftests/logger/.gitignore new file mode 100644 index 0000000..b1e5ec6 --- /dev/null +++ b/tools/testing/selftests/logger/.gitignore @@ -0,0 +1 @@ +logger-test diff --git a/tools/testing/selftests/logger/Makefile b/tools/testing/selftests/logger/Makefile new file mode 100644 index 0000000..02a9019 --- /dev/null +++ b/tools/testing/selftests/logger/Makefile @@ -0,0 +1,24 @@ +CFLAGS += -I../../../../usr/include/ +CFLAGS += -std=gnu99 +CFLAGS += -D_GNU_SOURCE +LDFLAGS = -pthread + +.PHONY: all clean + +include ../lib.mk + +TEST_CUSTOM_PROGS := $(OUTPUT)/logger-test +all: $(TEST_CUSTOM_PROGS) + +OBJS = \ + logger.o + +OBJS := $(patsubst %,$(OUTPUT)/%,$(OBJS)) + +$(TEST_CUSTOM_PROGS): $(OBJS) + $(CC) -o $(TEST_CUSTOM_PROGS) $(OBJS) $(LDFLAGS) + +$(OBJS): $(OUTPUT)/%.o: %.c + $(CC) -c $^ -o $@ $(CFLAGS) + +EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(OBJS) diff --git a/tools/testing/selftests/logger/logger.c b/tools/testing/selftests/logger/logger.c new file mode 100644 index 0000000..0446e79 --- /dev/null +++ b/tools/testing/selftests/logger/logger.c @@ -0,0 +1,155 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOGGER_SET_VERSION 44550 +#define LOGGER_SET_TAG 44551 +#define LOGGER_SET_PRIO 44552 + +#define handle_error_en(en, msg) \ + do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) + +#define BIT(nr) ((1UL) << (nr)) + +void *tstart(void *arg) +{ + int *fd = arg; + write(*fd, "child thread msg #1\nchild thread msg #2", 39); + return 0; +} + +int main(int ac, char *av[]) { + + char *device = "/dev/log_main"; + char *msg = "The Foo"; + char *tag = "stdio"; + int c, fd, s; + pid_t child; + pthread_t tid; + struct iovec vec[3]; + unsigned char prio = 4; + unsigned long test_mask = ~0UL; + + while (1) { + static struct option long_options[] = { + {"priority", required_argument, 0, 'p'}, + {"tag", required_argument, 0, 't'}, + {"test-mask", required_argument, 0, 'm'}, + {"device", required_argument, 0, 'd'}, + {0, 0, 0, 0} + }; + + c = getopt_long(ac, av, "p:t:m:d:", long_options, NULL); + if (c == -1) + break; + + switch (c) { + case 'p': + prio = (unsigned char) strtol(optarg, NULL, 10); + break; + case 't': + tag = strdup(optarg); + break; + case 'm': + test_mask = (unsigned char) strtol(optarg, NULL, 16); + break; + case 'd': + device = strdup(optarg); + break; + default: + exit(1); + } + } + + setlinebuf(stdout); + fd = open(device, O_WRONLY); + + if (ac >= 2) { + } + + if (ac == 3) { + } + + if (test_mask & BIT(0)) { + vec[0].iov_base = &prio; + vec[0].iov_len = 1; + vec[1].iov_base = tag; + vec[1].iov_len = strlen(tag) + 1; + vec[2].iov_base = msg; + vec[2].iov_len = strlen(msg) + 1; + + writev(fd, vec, 3); + if (test_mask & BIT(1)) { + msg = "line #1\nline #2"; + vec[2].iov_base = msg; + vec[2].iov_len = strlen(msg) + 1; + + writev(fd, vec, 3); + } + } + + ioctl(fd, LOGGER_SET_PRIO, prio); + ioctl(fd, LOGGER_SET_TAG, "\006\000\000\000stdio"); + + if (test_mask & BIT(2)) { + + write(fd, "The Foo From STDIO\n", 19); + + write(fd, "LINE #1\nLINE #2", 15); + write(fd, " CONTINUED\nONCE", 15); + write(fd, " AGAIN\n", 7); + } + + if (test_mask & BIT(3)) { + msg = malloc(8000); + if (!msg) + return 1; + + for (int i = 0; i < 8000; i++) + msg[i] = ' ' + (i % 96); + msg[7999] = '\n'; + write(fd, msg, 8000); + } + + if (test_mask & BIT(4)) { + child = fork(); + if (child < 0) { + return -1; + } else if (child == 0) { + sleep(1); + printf("child: %d\n", getpid()); + write(fd, "child 1\n", 8); + sleep(1); + write(fd, "child 2\n", 8); + close(fd); + return 0; + } + write(fd, "PARENT\n", 7); + printf("PARENT: %d\n", getpid()); + wait(&s); + } + + if (test_mask & BIT(5)) { + s = pthread_create(&tid, NULL, &tstart, &fd); + if (s != 0) + handle_error_en(s, "pthread_create"); + sleep(1); + write(fd, "PARENT THREAD\n", 14); + + s = pthread_join(tid, NULL); + if (s != 0) + handle_error_en(s, "pthread_join"); + } + + return 0; +} -- 2.7.4