From d1aac5b4085582618a2550d620f5d9ddb9f9591a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Wed, 14 Apr 2021 17:50:51 +0200 Subject: [PATCH] logger: introduce struct logger_set_tag MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Introduce dedicated structure for LOGGER_SET_TAG ioctl, instead of packing and unpacking arguments by hand. Change-Id: Ic3399ab37f55ba2b8a9a976f8c9495fc487fe7f3 Signed-off-by: Łukasz Stelmach --- drivers/staging/android/logger.c | 16 +++++++++------- include/uapi/linux/logger.h | 10 ++++++++++ tools/testing/selftests/logger/logger.c | 6 +++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c index d7707b6..a51294a 100644 --- a/drivers/staging/android/logger.c +++ b/drivers/staging/android/logger.c @@ -872,28 +872,30 @@ static long logger_set_prio(struct logger_writer *writer, void __user *arg) static long logger_set_tag(struct logger_writer *writer, void __user *arg) { + struct logger_set_tag tag; int len; char *p, *q; - if (copy_from_user(&len, arg, sizeof(int))) + if (copy_from_user(&tag, arg, sizeof(struct logger_set_tag))) return -EFAULT; - arg += sizeof(int); - + if (tag.len > LOGGER_ENTRY_MAX_PAYLOAD) + return -EINVAL; - p = kzalloc(len, GFP_KERNEL); + p = kzalloc(tag.len, GFP_KERNEL); if (!p) return -ENOMEM; - if (copy_from_user(p, arg, len)) { + if (copy_from_user(p, (void*)(uintptr_t)tag.ptr, tag.len)) { kfree(p); return -EFAULT; } - p[len-1] = '\0'; + p[tag.len - 1] = '\0'; + len = strlen(p); q = writer->tag; writer->tag = p; - writer->tag_len = len - 1; /* without NULL */ + writer->tag_len = len; kfree(q); return 0; diff --git a/include/uapi/linux/logger.h b/include/uapi/linux/logger.h index a02ac117e..8054a3e 100644 --- a/include/uapi/linux/logger.h +++ b/include/uapi/linux/logger.h @@ -74,6 +74,16 @@ struct logger_entry { char msg[0]; }; +/** + * struct logger_set_tag + * @len: Length of a NULL-terminated tag including '\0' + * @ptr: Pointer to a user buffer containing the tag + */ +struct logger_set_tag { + __u64 len; + __u64 ptr; +}; + #define LOGGER_LOG_RADIO "log_radio" /* radio-related messages */ #define LOGGER_LOG_EVENTS "log_events" /* system/hardware events */ #define LOGGER_LOG_SYSTEM "log_system" /* system/framework messages */ diff --git a/tools/testing/selftests/logger/logger.c b/tools/testing/selftests/logger/logger.c index 5f0bd3b..18a3ea7 100644 --- a/tools/testing/selftests/logger/logger.c +++ b/tools/testing/selftests/logger/logger.c @@ -30,6 +30,10 @@ int main(int ac, char *av[]) { char *device = "/dev/log_main"; char *msg = "The Foo"; char *tag = "stdio"; + struct logger_set_tag struct_tag = { + .len = 6, + .ptr = (uintptr_t)tag, + }; int c, fd, s; pid_t child; pthread_t tid; @@ -96,7 +100,7 @@ int main(int ac, char *av[]) { } ioctl(fd, LOGGER_SET_PRIO, prio); - ioctl(fd, LOGGER_SET_TAG, "\006\000\000\000stdio"); + ioctl(fd, LOGGER_SET_TAG, &struct_tag); if (test_mask & BIT(2)) { -- 2.7.4