lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  5 Aug 2021 08:14:34 -0700
From:   Tuo Li <islituo@...il.com>
To:     jlayton@...nel.org, idryomov@...il.com
Cc:     ceph-devel@...r.kernel.org, linux-kernel@...r.kernel.org,
        baijiaju1990@...il.com, Tuo Li <islituo@...il.com>,
        TOTE Robot <oslab@...nghua.edu.cn>
Subject: [PATCH v2] ceph: fix possible null-pointer dereference in ceph_mdsmap_decode()

kcalloc() is called to allocate memory for m->m_info, and if it fails,
ceph_mdsmap_destroy() behind the label out_err will be called:
  ceph_mdsmap_destroy(m);

In ceph_mdsmap_destroy(), m->m_info is dereferenced through:
  kfree(m->m_info[i].export_targets);

To fix this possible null-pointer dereference, check m->m_info before the 
for loop to free m->m_info[i].export_targets.

Reported-by: TOTE Robot <oslab@...nghua.edu.cn>
Signed-off-by: Tuo Li <islituo@...il.com>
---
v2:
* Put an "if (m->m_info)" around the for loop in ceph_mdsmap_destroy()
instead of freeing m and returning -ENOMEM in ceph_mdsmap_decode().
  Thank Jeff Layton for helpful advice.
---
 fs/ceph/mdsmap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index abd9af7727ad..26d6fa049b44 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -393,9 +393,11 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2)
 void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
 {
 	int i;
-
-	for (i = 0; i < m->possible_max_rank; i++)
-		kfree(m->m_info[i].export_targets);
+	
+	if (m->m_info) {
+		for (i = 0; i < m->possible_max_rank; i++)
+			kfree(m->m_info[i].export_targets);
+	}
 	kfree(m->m_info);
 	kfree(m->m_data_pg_pools);
 	kfree(m);
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ