aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2016-09-16 05:45:24 -0400
committerMiklos Szeredi <mszeredi@redhat.com>2016-09-21 10:37:07 -0400
commit6a45b3628ce4dcf7498b39c87d475bab6e2a9b24 (patch)
treefb203edbc99e09b1c34be42f203704a651530ddf
parent8eac98b8beb4711c4ab61822cac077fd6660e820 (diff)
ovl: Fix info leak in ovl_lookup_temp()
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> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Cc: <stable@vger.kernel.org> # v3.18+ Fixes: e9be9d5e76e3 ("overlay filesystem")
-rw-r--r--fs/overlayfs/dir.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 1560fdc09a5f..74e696426aae 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -14,6 +14,7 @@
14#include <linux/cred.h> 14#include <linux/cred.h>
15#include <linux/posix_acl.h> 15#include <linux/posix_acl.h>
16#include <linux/posix_acl_xattr.h> 16#include <linux/posix_acl_xattr.h>
17#include <linux/atomic.h>
17#include "overlayfs.h" 18#include "overlayfs.h"
18 19
19void ovl_cleanup(struct inode *wdir, struct dentry *wdentry) 20void ovl_cleanup(struct inode *wdir, struct dentry *wdentry)
@@ -37,8 +38,10 @@ struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry)
37{ 38{
38 struct dentry *temp; 39 struct dentry *temp;
39 char name[20]; 40 char name[20];
41 static atomic_t temp_id = ATOMIC_INIT(0);
40 42
41 snprintf(name, sizeof(name), "#%lx", (unsigned long) dentry); 43 /* counter is allowed to wrap, since temp dentries are ephemeral */
44 snprintf(name, sizeof(name), "#%x", atomic_inc_return(&temp_id));
42 45
43 temp = lookup_one_len(name, workdir, strlen(name)); 46 temp = lookup_one_len(name, workdir, strlen(name));
44 if (!IS_ERR(temp) && temp->d_inode) { 47 if (!IS_ERR(temp) && temp->d_inode) {