mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: android: logger: fix kuid/uid in logger_entry
@ 2014-10-30  2:23 Xiong Zhou
  2014-10-30  7:04 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Xiong Zhou @ 2014-10-30  2:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-team, nnk, john.stultz, gregkh, devel, jencce.kernel, arnd

From: Xiong Zhou <jencce.kernel@gmail.com>

struct logger_entry can be returned to userspace via ioctl,
so it is wrong to have a kuid_t member, fixing it to uid_t.
This was introduced by commit bd471258f2, to pass uidguid
type checks : UIDGID_STRICT_TYPE_CHECKS, which has been
removed from kernel in commit 261000a56b6.

Fixes: bd471258f2 (logger: use kuid_t instead of uid_t)
Signed-off-by: Xiong Zhou <jencce.kernel@gmail.com>
---
  drivers/staging/android/logger.c | 4 ++--
  drivers/staging/android/logger.h | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c
index 28b93d3..fb06bf2 100644
--- a/drivers/staging/android/logger.c
+++ b/drivers/staging/android/logger.c
@@ -252,7 +252,7 @@ static size_t get_next_entry_by_uid(struct logger_log *log,

  		entry = get_entry_header(log, off, &scratch);

-		if (uid_eq(entry->euid, euid))
+		if (entry->euid == __kuid_val(euid))
  			return off;

  		next_len = sizeof(struct logger_entry) + entry->len;
@@ -430,7 +430,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
  	header.tid = current->pid;
  	header.sec = now.tv_sec;
  	header.nsec = now.tv_nsec;
-	header.euid = current_euid();
+	header.euid = __kuid_val(current_euid());
  	header.len = count;
  	header.hdr_size = sizeof(struct logger_entry);

diff --git a/drivers/staging/android/logger.h b/drivers/staging/android/logger.h
index 70af7d8..cc6bbd9 100644
--- a/drivers/staging/android/logger.h
+++ b/drivers/staging/android/logger.h
@@ -66,7 +66,7 @@ struct logger_entry {
  	__s32		tid;
  	__s32		sec;
  	__s32		nsec;
-	kuid_t		euid;
+	uid_t		euid;
  	char		msg[0];
  };

-- 
1.9.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: android: logger: fix kuid/uid in logger_entry
  2014-10-30  2:23 [PATCH] staging: android: logger: fix kuid/uid in logger_entry Xiong Zhou
@ 2014-10-30  7:04 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2014-10-30  7:04 UTC (permalink / raw)
  To: Xiong Zhou; +Cc: linux-kernel, kernel-team, nnk, john.stultz, gregkh, devel

On Thursday 30 October 2014 10:23:31 Xiong Zhou wrote:
> From: Xiong Zhou <jencce.kernel@gmail.com>
> 
> struct logger_entry can be returned to userspace via ioctl,
> so it is wrong to have a kuid_t member, fixing it to uid_t.
> This was introduced by commit bd471258f2, to pass uidguid
> type checks : UIDGID_STRICT_TYPE_CHECKS, which has been
> removed from kernel in commit 261000a56b6.
> 
> Fixes: bd471258f2 (logger: use kuid_t instead of uid_t)
> Signed-off-by: Xiong Zhou <jencce.kernel@gmail.com>

Sorry, but this isn't good.

You had an earlier patch that introduced a bug by hiding a warning,
and now you send a new patch to hide the bug better instead of
fixing it?

> diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c
> index 28b93d3..fb06bf2 100644
> --- a/drivers/staging/android/logger.c
> +++ b/drivers/staging/android/logger.c
> @@ -252,7 +252,7 @@ static size_t get_next_entry_by_uid(struct logger_log *log,
> 
>                 entry = get_entry_header(log, off, &scratch);
> 
> -               if (uid_eq(entry->euid, euid))
> +               if (entry->euid == __kuid_val(euid))
>                         return off;
> 
>                 next_len = sizeof(struct logger_entry) + entry->len;

The code above was correct, you are just breaking it more.

> @@ -430,7 +430,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
>         header.tid = current->pid;
>         header.sec = now.tv_sec;
>         header.nsec = now.tv_nsec;
> -       header.euid = current_euid();
> +       header.euid = __kuid_val(current_euid());
>         header.len = count;
>         header.hdr_size = sizeof(struct logger_entry);
> 

This writes to the internal data structure, so here you should still use
kuid_t. The problem is that you are later leaking this to user space,
so a user in one container can read entries from a user with the same
uid in another container, and that a process calling read() with the
r_all bit set will get entries with uids from all containers, using
the kernel-internal uid values instead of the ones valid for the current
container.

	Arnd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-30  7:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-30  2:23 [PATCH] staging: android: logger: fix kuid/uid in logger_entry Xiong Zhou
2014-10-30  7:04 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®