All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntfs: move check for valid resident attribute offset and length
@ 2021-02-14 22:12 Rustam Kovhaev
  2021-02-16  2:40 ` Anton Altaparmakov
  0 siblings, 1 reply; 3+ messages in thread
From: Rustam Kovhaev @ 2021-02-14 22:12 UTC (permalink / raw)
  To: anton, linux-ntfs-dev; +Cc: linux-kernel, gregkh, Rustam Kovhaev

we should check for valid resident atribute offset and length before
loading STANDARD_INFORMATION attribute in ntfs_read_locked_inode()
let's make that check a bit earlier in the same function to avoid
use-after-free bug

Reported-and-tested-by: syzbot+c584225dabdea2f71969@syzkaller.appspotmail.com
Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
Link: https://syzkaller.appspot.com/bug?extid=c584225dabdea2f71969
---
 fs/ntfs/inode.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index f7e4cbc26eaf..70745aea5106 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -629,6 +629,13 @@ static int ntfs_read_locked_inode(struct inode *vi)
 	}
 	a = ctx->attr;
 	/* Get the standard information attribute value. */
+	if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
+			+ le32_to_cpu(
+			a->data.resident.value_length) >
+			(u8 *)ctx->mrec + vol->mft_record_size) {
+		ntfs_error(vi->i_sb, "Corrupt attribute list in inode.");
+		goto unm_err_out;
+	}
 	si = (STANDARD_INFORMATION*)((u8*)a +
 			le16_to_cpu(a->data.resident.value_offset));
 
@@ -731,14 +738,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
 				goto unm_err_out;
 			}
 		} else /* if (!a->non_resident) */ {
-			if ((u8*)a + le16_to_cpu(a->data.resident.value_offset)
-					+ le32_to_cpu(
-					a->data.resident.value_length) >
-					(u8*)ctx->mrec + vol->mft_record_size) {
-				ntfs_error(vi->i_sb, "Corrupt attribute list "
-						"in inode.");
-				goto unm_err_out;
-			}
 			/* Now copy the attribute list. */
 			memcpy(ni->attr_list, (u8*)a + le16_to_cpu(
 					a->data.resident.value_offset),
-- 
2.30.0


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

* Re: [PATCH] ntfs: move check for valid resident attribute offset and length
  2021-02-14 22:12 [PATCH] ntfs: move check for valid resident attribute offset and length Rustam Kovhaev
@ 2021-02-16  2:40 ` Anton Altaparmakov
  2021-02-16 16:24   ` Rustam Kovhaev
  0 siblings, 1 reply; 3+ messages in thread
From: Anton Altaparmakov @ 2021-02-16  2:40 UTC (permalink / raw)
  To: Rustam Kovhaev; +Cc: linux-ntfs-dev, LKML, gregkh

Hi Rustam,

Thank you for the patch but it is not quite correct:

1) The first delta: yes that is a good idea to add this check but the error message is incorrect.  It should say "Corrupt standard information attribute in inode." instead.

2) The second delta: The check of the attribute list attribute needs to remain, i.e. your second delta needs to be deleted.

Please could you address both of the above comments and then resend?  Please then also add: "Acked-by: Anton Altaparmakov <anton@tuxera.com>" to the patch.

Thanks a lot in advance!

Best regards,

	Anton

> On 14 Feb 2021, at 22:12, Rustam Kovhaev <rkovhaev@gmail.com> wrote:
> 
> we should check for valid resident atribute offset and length before
> loading STANDARD_INFORMATION attribute in ntfs_read_locked_inode()
> let's make that check a bit earlier in the same function to avoid
> use-after-free bug
> 
> Reported-and-tested-by: syzbot+c584225dabdea2f71969@syzkaller.appspotmail.com
> Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
> Link: https://syzkaller.appspot.com/bug?extid=c584225dabdea2f71969
> ---
> fs/ntfs/inode.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
> index f7e4cbc26eaf..70745aea5106 100644
> --- a/fs/ntfs/inode.c
> +++ b/fs/ntfs/inode.c
> @@ -629,6 +629,13 @@ static int ntfs_read_locked_inode(struct inode *vi)
> 	}
> 	a = ctx->attr;
> 	/* Get the standard information attribute value. */
> +	if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
> +			+ le32_to_cpu(
> +			a->data.resident.value_length) >
> +			(u8 *)ctx->mrec + vol->mft_record_size) {
> +		ntfs_error(vi->i_sb, "Corrupt attribute list in inode.");
> +		goto unm_err_out;
> +	}
> 	si = (STANDARD_INFORMATION*)((u8*)a +
> 			le16_to_cpu(a->data.resident.value_offset));
> 
> @@ -731,14 +738,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
> 				goto unm_err_out;
> 			}
> 		} else /* if (!a->non_resident) */ {
> -			if ((u8*)a + le16_to_cpu(a->data.resident.value_offset)
> -					+ le32_to_cpu(
> -					a->data.resident.value_length) >
> -					(u8*)ctx->mrec + vol->mft_record_size) {
> -				ntfs_error(vi->i_sb, "Corrupt attribute list "
> -						"in inode.");
> -				goto unm_err_out;
> -			}
> 			/* Now copy the attribute list. */
> 			memcpy(ni->attr_list, (u8*)a + le16_to_cpu(
> 					a->data.resident.value_offset),
> -- 
> 2.30.0
> 


-- 
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer


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

* Re: [PATCH] ntfs: move check for valid resident attribute offset and length
  2021-02-16  2:40 ` Anton Altaparmakov
@ 2021-02-16 16:24   ` Rustam Kovhaev
  0 siblings, 0 replies; 3+ messages in thread
From: Rustam Kovhaev @ 2021-02-16 16:24 UTC (permalink / raw)
  To: Anton Altaparmakov; +Cc: linux-ntfs-dev, LKML, gregkh

On Tue, Feb 16, 2021 at 02:40:37AM +0000, Anton Altaparmakov wrote:
> Hi Rustam,
> 
> Thank you for the patch but it is not quite correct:
> 
> 1) The first delta: yes that is a good idea to add this check but the error message is incorrect.  It should say "Corrupt standard information attribute in inode." instead.
> 
> 2) The second delta: The check of the attribute list attribute needs to remain, i.e. your second delta needs to be deleted.
> 
> Please could you address both of the above comments and then resend?  Please then also add: "Acked-by: Anton Altaparmakov <anton@tuxera.com>" to the patch.
> 
> Thanks a lot in advance!
> 
> Best regards,
> 
> 	Anton
> 
hi Anton, thank you for the review! I'll resend the patch!

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

end of thread, other threads:[~2021-02-16 16:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-14 22:12 [PATCH] ntfs: move check for valid resident attribute offset and length Rustam Kovhaev
2021-02-16  2:40 ` Anton Altaparmakov
2021-02-16 16:24   ` Rustam Kovhaev

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.