* [PATCH] ovl: Fix info leak in ovl_lookup_temp()
@ 2016-09-16 9:45 Richard Weinberger
2016-09-16 20:36 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2016-09-16 9:45 UTC (permalink / raw)
To: miklos; +Cc: linux-unionfs, linux-kernel, keescook, Richard Weinberger
The function uses the memory address of a struct dentry as unique id.
While the address-based directory entry is only visible to root
it is IMHO still worth fixing since the temporary name does not have
to be a kernel address. It can be any unique number. Replace it by an
atomic integer which is allowed to wrap around.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/overlayfs/dir.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 1560fdc..6e00a08 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -14,6 +14,7 @@
#include <linux/cred.h>
#include <linux/posix_acl.h>
#include <linux/posix_acl_xattr.h>
+#include <linux/atomic.h>
#include "overlayfs.h"
void ovl_cleanup(struct inode *wdir, struct dentry *wdentry)
@@ -37,8 +38,9 @@ struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry)
{
struct dentry *temp;
char name[20];
+ static atomic_t temp_id = ATOMIC_INIT(0);
- snprintf(name, sizeof(name), "#%lx", (unsigned long) dentry);
+ snprintf(name, sizeof(name), "#%x", atomic_inc_return(&temp_id));
temp = lookup_one_len(name, workdir, strlen(name));
if (!IS_ERR(temp) && temp->d_inode) {
--
2.7.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ovl: Fix info leak in ovl_lookup_temp()
2016-09-16 9:45 [PATCH] ovl: Fix info leak in ovl_lookup_temp() Richard Weinberger
@ 2016-09-16 20:36 ` Kees Cook
2016-09-21 14:38 ` Miklos Szeredi
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2016-09-16 20:36 UTC (permalink / raw)
To: Richard Weinberger; +Cc: Miklos Szeredi, linux-unionfs, LKML
On Fri, Sep 16, 2016 at 2:45 AM, Richard Weinberger <richard@nod.at> wrote:
> The function uses the memory address of a struct dentry as unique id.
> While the address-based directory entry is only visible to root
> it is IMHO still worth fixing since the temporary name does not have
> to be a kernel address. It can be any unique number. Replace it by an
> atomic integer which is allowed to wrap around.
>
> Signed-off-by: Richard Weinberger <richard@nod.at>
Nice catch!
Reviewed-by: Kees Cook <keescook@chromium.org>
We'll have to remember this for when atomic_t wrap checking gets added
to mark this as "intended to wrap".
Thanks,
-Kees
> ---
> fs/overlayfs/dir.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
> index 1560fdc..6e00a08 100644
> --- a/fs/overlayfs/dir.c
> +++ b/fs/overlayfs/dir.c
> @@ -14,6 +14,7 @@
> #include <linux/cred.h>
> #include <linux/posix_acl.h>
> #include <linux/posix_acl_xattr.h>
> +#include <linux/atomic.h>
> #include "overlayfs.h"
>
> void ovl_cleanup(struct inode *wdir, struct dentry *wdentry)
> @@ -37,8 +38,9 @@ struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry)
> {
> struct dentry *temp;
> char name[20];
> + static atomic_t temp_id = ATOMIC_INIT(0);
>
> - snprintf(name, sizeof(name), "#%lx", (unsigned long) dentry);
> + snprintf(name, sizeof(name), "#%x", atomic_inc_return(&temp_id));
>
> temp = lookup_one_len(name, workdir, strlen(name));
> if (!IS_ERR(temp) && temp->d_inode) {
> --
> 2.7.3
>
--
Kees Cook
Nexus Security
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ovl: Fix info leak in ovl_lookup_temp()
2016-09-16 20:36 ` Kees Cook
@ 2016-09-21 14:38 ` Miklos Szeredi
0 siblings, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2016-09-21 14:38 UTC (permalink / raw)
To: Kees Cook; +Cc: Richard Weinberger, linux-unionfs, LKML
On Fri, Sep 16, 2016 at 10:36 PM, Kees Cook <keescook@chromium.org> wrote:
> On Fri, Sep 16, 2016 at 2:45 AM, Richard Weinberger <richard@nod.at> wrote:
>> The function uses the memory address of a struct dentry as unique id.
>> While the address-based directory entry is only visible to root
>> it is IMHO still worth fixing since the temporary name does not have
>> to be a kernel address. It can be any unique number. Replace it by an
>> atomic integer which is allowed to wrap around.
>>
>> Signed-off-by: Richard Weinberger <richard@nod.at>
Thanks, applied and pushed to #overlayfs-next.
Thanks,
Miklos
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-21 14:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-16 9:45 [PATCH] ovl: Fix info leak in ovl_lookup_temp() Richard Weinberger
2016-09-16 20:36 ` Kees Cook
2016-09-21 14:38 ` Miklos Szeredi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.