[PATCH] fs/ntfs3: Add check for kmemdup

Jiasheng Jiang posted 1 patch 3 years, 4 months ago
fs/ntfs3/fslog.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] fs/ntfs3: Add check for kmemdup
Posted by Jiasheng Jiang 3 years, 4 months ago
Since the kmemdup may return NULL pointer,
it should be better to add check for the return value
in order to avoid NULL pointer dereference.

Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 fs/ntfs3/fslog.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 0d611a6c5511..eb7cf8a69607 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -4277,6 +4277,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
 	rec_len -= t32;
 
 	attr_names = kmemdup(Add2Ptr(lrh, t32), rec_len, GFP_NOFS);
+	if (!attr_names) {
+		err = -ENOMEM;
+		goto out;
+	}
 
 	lcb_put(lcb);
 	lcb = NULL;
-- 
2.25.1
Re: [PATCH] fs/ntfs3: Add check for kmemdup
Posted by Konstantin Komarov 3 years, 3 months ago
On 23.11.2022 12:48, Jiasheng Jiang wrote:
> Since the kmemdup may return NULL pointer,
> it should be better to add check for the return value
> in order to avoid NULL pointer dereference.
>
> Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>   fs/ntfs3/fslog.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
> index 0d611a6c5511..eb7cf8a69607 100644
> --- a/fs/ntfs3/fslog.c
> +++ b/fs/ntfs3/fslog.c
> @@ -4277,6 +4277,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
>   	rec_len -= t32;
>   
>   	attr_names = kmemdup(Add2Ptr(lrh, t32), rec_len, GFP_NOFS);
> +	if (!attr_names) {
> +		err = -ENOMEM;
> +		goto out;
> +	}
>   
>   	lcb_put(lcb);
>   	lcb = NULL;
Thank you for your work, applied!