!55 [sync] PR-50: fix double free on error in read_raid56

From: @openeuler-sync-bot 
Reviewed-by: @swf504 
Signed-off-by: @swf504
This commit is contained in:
openeuler-ci-bot 2024-07-05 03:51:51 +00:00 committed by Gitee
commit 96e5cec947
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,41 @@
From 844caf8639826ed4ddc6dc7b3ba30bd19f9b21d8 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Thu, 4 Apr 2024 00:55:47 +0200
Subject: [PATCH] btrfs-progs: fix double free on error in read_raid56()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reported by 'gcc -fanalyzer':
kernel-shared/extent_io.c: In function read_raid56:
./include/kerncompat.h:393:18: warning: dereference of NULL pointers [CWE-476] [-Wanalyzer-null-dereference]
After allocation of the pointers array fails it's dereferenced in the
exit block. We can return immediately instead.
Signed-off-by: David Sterba <dsterba@suse.com>
---
kernel-shared/extent_io.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c
index f112983..2063c1d 100644
--- a/kernel-shared/extent_io.c
+++ b/kernel-shared/extent_io.c
@@ -807,10 +807,9 @@ static int read_raid56(struct btrfs_fs_info *fs_info, void *buf, u64 logical,
ASSERT(len <= BTRFS_STRIPE_LEN);
pointers = calloc(num_stripes, sizeof(void *));
- if (!pointers) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!pointers)
+ return -ENOMEM;
+
/* Allocate memory for the full stripe */
for (i = 0; i < num_stripes; i++) {
pointers[i] = malloc(BTRFS_STRIPE_LEN);
--
2.27.0

View File

@ -1,12 +1,13 @@
Name: btrfs-progs
Version: 6.0
Release: 2
Release: 3
Summary: btrfs userspace programs
License: GPLv2 and GPL+ and LGPL-2.1+ and GPL-3.0+ and LGPL-2.1 and MIT
URL: https://btrfs.wiki.kernel.org/index.php/Main_Page
Source0: https://www.kernel.org/pub/linux/kernel/people/kdave/%{name}/%{name}-v%{version}.tar.xz
Patch0001: 0001-fix-exclusive-op-enqueue-timeout.patch
Patch0002: 0002-fix-double-free-on-error-in-read_raid56.patch
BuildRequires: python3-devel >= 3.4
BuildRequires: libacl-devel, e2fsprogs-devel, libblkid-devel, libuuid-devel, zlib-devel, libzstd-devel, lzo-devel, systemd-devel
@ -72,6 +73,9 @@ make mandir=%{_mandir} bindir=%{_sbindir} libdir=%{_libdir} incdir=%{_includedir
%{_mandir}/man8/*.gz
%changelog
* Tue Jul 2 2024 zhangyaqi <zhangyaqi@kylinos.cn> - 6.0-3
- fix double free on error in read_raid56()
* Fri Apr 19 2024 cenhuilin <cenhuilin@kylinos.cn> - 6.0-2
- fix exclusive op enqueue timeout