[Ocfs2-tools-devel] [PATCH V1] mount.ocfs2: Fix double free problems when remounting a device

Shichangkuo shi.changkuo at h3c.com
Sun Feb 11 18:47:48 PST 2018


Hi Joseph,
Thanks for your reply.

> -----Original Message-----
> From: Joseph Qi [mailto:jiangqi903 at gmail.com]
> Sent: Monday, February 12, 2018 9:05 AM
> To: shichangkuo (Cloud); Ocfs2-tools-devel at oss.oracle.com
> Subject: Re: [Ocfs2-tools-devel] [PATCH V1] mount.ocfs2: Fix double free
> problems when remounting a device
>
>
>
> On 18/2/11 20:39, Shichangkuo wrote:
> > From 60985d3705d401427c5db4116716fc5bc5223662 Mon Sep 17
> 00:00:00 2001
> > From: shichangkuo <shi.changkuo at h3c.com>
> > Date: Wed, 7 Feb 2018 17:25:08 +0800
> > Subject: [PATCH] mount.ocfs2: Fix double free problems when remounting
> > a  device
> >
> The above should be eliminated in your patch body.
>
OK, I will revise it in next version.

> > When remounting a device, the issue happens:
> > ~# mount -o remount,rw /vms/share
> > *** Error in `/sbin/mount.ocfs2': double free or corruption (!prev):
> > 0x0000000000b305a0
> > *** Aborted
> >
> > When updating the mtab, we should free the old mnt_opts, and duplicate
> > a new one from instead->mnt_opts.
> >
> > Signed-off-by: shichangkuo <shi.changkuo at h3c.com>
> > ---
> >  mount.ocfs2/fstab.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/mount.ocfs2/fstab.c b/mount.ocfs2/fstab.c index
> > d3fc617..59cd369 100644
> > --- a/mount.ocfs2/fstab.c
> > +++ b/mount.ocfs2/fstab.c
> > @@ -612,7 +612,8 @@ update_mtab (const char *dir, struct my_mntent
> *instead) {
> >                         }
> >                 } else {
> >                         /* A remount */
> > -                       mc->m.mnt_opts = instead->mnt_opts;
> > +                       my_free(mc->m.mnt_opts);
> Why we have to free here?
>
mc-> mnt_opts was malloced in read_mntentchn, so we have to free it, otherwise it could cause memory leak.
If we change pointer mc-> mnt_opts directly, it will have double free, therefore we should duplicate it from instead->mnt_opts.

Thanks,
Changkuo

> Thanks,
> Joseph
>
> > +                       mc->m.mnt_opts =
> xstrdup(instead->mnt_opts);
> >                 }
> >         } else if (instead) {
> >                 /* not found, add a new entry */
> > --
> > 1.7.9.5
-------------------------------------------------------------------------------------------------------------------------------------
本邮件及其附件含有新华三技术有限公司的保密信息,仅限于发送给上面地址中列出
的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、
或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本
邮件!
This e-mail and its attachments contain confidential information from New H3C, which is
intended only for the person or entity whose address is listed above. Any use of the
information contained herein in any way (including, but not limited to, total or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender
by phone or email immediately and delete it!


More information about the Ocfs2-tools-devel mailing list