jfs: Fix inconsistency between memory allocation and ea_buf->max_size

Message ID 1532528839-20131-2-git-send-email-paolo.pisati@canonical.com
State New
Headers show
Series
  • jfs: Fix inconsistency between memory allocation and ea_buf->max_size
Related show

Commit Message

Paolo Pisati July 25, 2018, 2:27 p.m.
From: Shankara Pailoor <shankarapailoor@gmail.com>

CVE-2018-12233

The code is assuming the buffer is max_size length, but we weren't
allocating enough space for it.

Signed-off-by: Shankara Pailoor <shankarapailoor@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
(cherry picked from commit 92d34134193e5b129dc24f8d79cb9196626e8d7a)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 fs/jfs/xattr.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Stefan Bader July 25, 2018, 2:40 p.m. | #1
On 25.07.2018 16:27, Paolo Pisati wrote:
> From: Shankara Pailoor <shankarapailoor@gmail.com>
> 
> CVE-2018-12233
> 
> The code is assuming the buffer is max_size length, but we weren't
> allocating enough space for it.
> 
> Signed-off-by: Shankara Pailoor <shankarapailoor@gmail.com>
> Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
> (cherry picked from commit 92d34134193e5b129dc24f8d79cb9196626e8d7a)
> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  fs/jfs/xattr.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
> index 6910662..54da0d6 100644
> --- a/fs/jfs/xattr.c
> +++ b/fs/jfs/xattr.c
> @@ -493,15 +493,17 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
>  	if (size > PSIZE) {
>  		/*
>  		 * To keep the rest of the code simple.  Allocate a
> -		 * contiguous buffer to work with
> +		 * contiguous buffer to work with. Make the buffer large
> +		 * enough to make use of the whole extent.
>  		 */
> -		ea_buf->xattr = kmalloc(size, GFP_KERNEL);
> +		ea_buf->max_size = (size + sb->s_blocksize - 1) &
> +		    ~(sb->s_blocksize - 1);
> +
> +		ea_buf->xattr = kmalloc(ea_buf->max_size, GFP_KERNEL);
>  		if (ea_buf->xattr == NULL)
>  			return -ENOMEM;
>  
>  		ea_buf->flag = EA_MALLOC;
> -		ea_buf->max_size = (size + sb->s_blocksize - 1) &
> -		    ~(sb->s_blocksize - 1);
>  
>  		if (ea_size == 0)
>  			return 0;
>

Patch

diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 6910662..54da0d6 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -493,15 +493,17 @@  static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
 	if (size > PSIZE) {
 		/*
 		 * To keep the rest of the code simple.  Allocate a
-		 * contiguous buffer to work with
+		 * contiguous buffer to work with. Make the buffer large
+		 * enough to make use of the whole extent.
 		 */
-		ea_buf->xattr = kmalloc(size, GFP_KERNEL);
+		ea_buf->max_size = (size + sb->s_blocksize - 1) &
+		    ~(sb->s_blocksize - 1);
+
+		ea_buf->xattr = kmalloc(ea_buf->max_size, GFP_KERNEL);
 		if (ea_buf->xattr == NULL)
 			return -ENOMEM;
 
 		ea_buf->flag = EA_MALLOC;
-		ea_buf->max_size = (size + sb->s_blocksize - 1) &
-		    ~(sb->s_blocksize - 1);
 
 		if (ea_size == 0)
 			return 0;