From: Jeff Layton <jlayton@kernel.org> To: Tuo Li <islituo@gmail.com>, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, TOTE Robot <oslab@tsinghua.edu.cn> Subject: Re: [PATCH v2] ceph: fix possible null-pointer dereference in ceph_mdsmap_decode() Date: Thu, 05 Aug 2021 15:25:53 -0400 [thread overview] Message-ID: <ce95d07e585ce8ff184c26c9b26c8211921f1546.camel@kernel.org> (raw) In-Reply-To: <20210805151434.142619-1-islituo@gmail.com> On Thu, 2021-08-05 at 08:14 -0700, Tuo Li wrote: > 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@tsinghua.edu.cn> > Signed-off-by: Tuo Li <islituo@gmail.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); > + This patch added some whitespace damage above. I went ahead and fixed it up before merging. > + if (m->m_info) { > + for (i = 0; i < m->possible_max_rank; i++) > + kfree(m->m_info[i].export_targets); > + } > kfree(m->m_info); I also moved the above kfree into the if statement since we have to check it anyway (no need to do it twice). > kfree(m->m_data_pg_pools); > kfree(m); Merged! Thanks for the patch. -- Jeff Layton <jlayton@kernel.org>
prev parent reply other threads:[~2021-08-05 19:25 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-05 15:14 Tuo Li 2021-08-05 19:25 ` Jeff Layton [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ce95d07e585ce8ff184c26c9b26c8211921f1546.camel@kernel.org \ --to=jlayton@kernel.org \ --cc=baijiaju1990@gmail.com \ --cc=ceph-devel@vger.kernel.org \ --cc=idryomov@gmail.com \ --cc=islituo@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=oslab@tsinghua.edu.cn \ --subject='Re: [PATCH v2] ceph: fix possible null-pointer dereference in ceph_mdsmap_decode()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).