linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref
@ 2018-10-20 11:07 Hou Tao
  2018-12-09  6:34 ` Hou Tao
  2018-12-09  6:52 ` Boris Brezillon
  0 siblings, 2 replies; 5+ messages in thread
From: Hou Tao @ 2018-10-20 11:07 UTC (permalink / raw)
  To: linux-mtd, dwmw2; +Cc: linux-kernel, richard.weinberger, boris.brezillon

When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid
because these fields will be reused as xref->ino or xref->xid,
so access xref->ic->ino or xref->xd->xid will lead to Oops.

Fix the problem by checking whether or not it is a dead xref.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 fs/jffs2/xattr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index 3d40fe02b003..0c4c7891556d 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
 	ref->xseqno = xseqno;
 	jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
 
-	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
+	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n",
+			je32_to_cpu(rr.ino), je32_to_cpu(rr.xid));
 
 	return 0;
 }
@@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
 	rc = save_xattr_ref(c, ref);
 	if (!rc)
 		dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
-			  ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
+				is_xattr_ref_dead(ref) ?
+					ref->ino : ref->ic->ino,
+				is_xattr_ref_dead(ref) ?
+					ref->xid : ref->xd->xid,
+				old_ofs, ref_offset(ref->node));
  out:
 	if (!rc)
 		jffs2_mark_node_obsolete(c, raw);
-- 
2.16.2.dirty


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref
  2018-10-20 11:07 [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref Hou Tao
@ 2018-12-09  6:34 ` Hou Tao
  2018-12-09  6:52 ` Boris Brezillon
  1 sibling, 0 replies; 5+ messages in thread
From: Hou Tao @ 2018-12-09  6:34 UTC (permalink / raw)
  To: linux-mtd, dwmw2; +Cc: richard.weinberger, boris.brezillon, linux-kernel

ping ?

On 2018/10/20 19:07, Hou Tao wrote:
> When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid
> because these fields will be reused as xref->ino or xref->xid,
> so access xref->ic->ino or xref->xd->xid will lead to Oops.
> 
> Fix the problem by checking whether or not it is a dead xref.
> 
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  fs/jffs2/xattr.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
> index 3d40fe02b003..0c4c7891556d 100644
> --- a/fs/jffs2/xattr.c
> +++ b/fs/jffs2/xattr.c
> @@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
>  	ref->xseqno = xseqno;
>  	jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
>  
> -	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
> +	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n",
> +			je32_to_cpu(rr.ino), je32_to_cpu(rr.xid));
>  
>  	return 0;
>  }
> @@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
>  	rc = save_xattr_ref(c, ref);
>  	if (!rc)
>  		dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
> -			  ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
> +				is_xattr_ref_dead(ref) ?
> +					ref->ino : ref->ic->ino,
> +				is_xattr_ref_dead(ref) ?
> +					ref->xid : ref->xd->xid,
> +				old_ofs, ref_offset(ref->node));
>   out:
>  	if (!rc)
>  		jffs2_mark_node_obsolete(c, raw);
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref
  2018-10-20 11:07 [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref Hou Tao
  2018-12-09  6:34 ` Hou Tao
@ 2018-12-09  6:52 ` Boris Brezillon
  2018-12-13 21:53   ` Richard Weinberger
  1 sibling, 1 reply; 5+ messages in thread
From: Boris Brezillon @ 2018-12-09  6:52 UTC (permalink / raw)
  To: Hou Tao; +Cc: linux-mtd, dwmw2, linux-kernel, richard.weinberger

On Sat, 20 Oct 2018 19:07:53 +0800
Hou Tao <houtao1@huawei.com> wrote:

> When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid
> because these fields will be reused as xref->ino or xref->xid,
> so access xref->ic->ino or xref->xd->xid will lead to Oops.
> 
> Fix the problem by checking whether or not it is a dead xref.
> 
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  fs/jffs2/xattr.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
> index 3d40fe02b003..0c4c7891556d 100644
> --- a/fs/jffs2/xattr.c
> +++ b/fs/jffs2/xattr.c
> @@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
>  	ref->xseqno = xseqno;
>  	jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
>  
> -	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
> +	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n",
> +			je32_to_cpu(rr.ino), je32_to_cpu(rr.xid));

Nit: align the second line on the open parens (same applies to the
other chunk).

Sorry, I can't comment on the actual change. I'll let Richard look
at it.

>  
>  	return 0;
>  }
> @@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
>  	rc = save_xattr_ref(c, ref);
>  	if (!rc)
>  		dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
> -			  ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
> +				is_xattr_ref_dead(ref) ?
> +					ref->ino : ref->ic->ino,
> +				is_xattr_ref_dead(ref) ?
> +					ref->xid : ref->xd->xid,
> +				old_ofs, ref_offset(ref->node));
>   out:
>  	if (!rc)
>  		jffs2_mark_node_obsolete(c, raw);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref
  2018-12-09  6:52 ` Boris Brezillon
@ 2018-12-13 21:53   ` Richard Weinberger
  2018-12-15 13:17     ` Hou Tao
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2018-12-13 21:53 UTC (permalink / raw)
  To: boris.brezillon; +Cc: houtao1, linux-mtd, David Woodhouse, LKML

On Sun, Dec 9, 2018 at 7:52 AM Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
>
> On Sat, 20 Oct 2018 19:07:53 +0800
> Hou Tao <houtao1@huawei.com> wrote:
>
> > When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid
> > because these fields will be reused as xref->ino or xref->xid,
> > so access xref->ic->ino or xref->xd->xid will lead to Oops.
> >
> > Fix the problem by checking whether or not it is a dead xref.
> >
> > Signed-off-by: Hou Tao <houtao1@huawei.com>
> > ---
> >  fs/jffs2/xattr.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
> > index 3d40fe02b003..0c4c7891556d 100644
> > --- a/fs/jffs2/xattr.c
> > +++ b/fs/jffs2/xattr.c
> > @@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
> >       ref->xseqno = xseqno;
> >       jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
> >
> > -     dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
> > +     dbg_xattr("success on saving xref (ino=%u, xid=%u)\n",
> > +                     je32_to_cpu(rr.ino), je32_to_cpu(rr.xid));
>
> Nit: align the second line on the open parens (same applies to the
> other chunk).
>
> Sorry, I can't comment on the actual change. I'll let Richard look
> at it.
>
> >
> >       return 0;
> >  }
> > @@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
> >       rc = save_xattr_ref(c, ref);
> >       if (!rc)
> >               dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
> > -                       ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
> > +                             is_xattr_ref_dead(ref) ?
> > +                                     ref->ino : ref->ic->ino,
> > +                             is_xattr_ref_dead(ref) ?
> > +                                     ref->xid : ref->xd->xid,
> > +                             old_ofs, ref_offset(ref->node));
> >   out:
> >       if (!rc)
> >               jffs2_mark_node_obsolete(c, raw);
>

Since is_xattr_ref_dead() is cheap, can you please add two macros.
Something like:
static inline uint32_t xattr_ref_ino(struct jffs2_xattr_ref *ref) {
 if (is_xattr_ref_dead(ref))
  return ref>ino;
 else
  return ref->ic->ino;
}

Same for xid.
-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref
  2018-12-13 21:53   ` Richard Weinberger
@ 2018-12-15 13:17     ` Hou Tao
  0 siblings, 0 replies; 5+ messages in thread
From: Hou Tao @ 2018-12-15 13:17 UTC (permalink / raw)
  To: Richard Weinberger, boris.brezillon; +Cc: linux-mtd, David Woodhouse, LKML



On 2018/12/14 5:53, Richard Weinberger wrote:
> On Sun, Dec 9, 2018 at 7:52 AM Boris Brezillon
> <boris.brezillon@bootlin.com> wrote:
>>
>> On Sat, 20 Oct 2018 19:07:53 +0800
>> Hou Tao <houtao1@huawei.com> wrote:
>>
>>> When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid
>>> because these fields will be reused as xref->ino or xref->xid,
>>> so access xref->ic->ino or xref->xd->xid will lead to Oops.
>>>
>>> Fix the problem by checking whether or not it is a dead xref.
>>>
>>> Signed-off-by: Hou Tao <houtao1@huawei.com>
>>> ---
>>>  fs/jffs2/xattr.c | 9 +++++++--
>>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
>>> index 3d40fe02b003..0c4c7891556d 100644
>>> --- a/fs/jffs2/xattr.c
>>> +++ b/fs/jffs2/xattr.c
>>> @@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
>>>       ref->xseqno = xseqno;
>>>       jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
>>>
>>> -     dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
>>> +     dbg_xattr("success on saving xref (ino=%u, xid=%u)\n",
>>> +                     je32_to_cpu(rr.ino), je32_to_cpu(rr.xid));
>>
>> Nit: align the second line on the open parens (same applies to the
>> other chunk).

Thanks for pointing it out, I will fix them.

>> Sorry, I can't comment on the actual change. I'll let Richard look
>> at it.
>>
>>>
>>>       return 0;
>>>  }
>>> @@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
>>>       rc = save_xattr_ref(c, ref);
>>>       if (!rc)
>>>               dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
>>> -                       ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
>>> +                             is_xattr_ref_dead(ref) ?
>>> +                                     ref->ino : ref->ic->ino,
>>> +                             is_xattr_ref_dead(ref) ?
>>> +                                     ref->xid : ref->xd->xid,
>>> +                             old_ofs, ref_offset(ref->node));
>>>   out:
>>>       if (!rc)
>>>               jffs2_mark_node_obsolete(c, raw);
>>
> 
> Since is_xattr_ref_dead() is cheap, can you please add two macros.
> Something like:
> static inline uint32_t xattr_ref_ino(struct jffs2_xattr_ref *ref) {
>  if (is_xattr_ref_dead(ref))
>   return ref>ino;
>  else
>   return ref->ic->ino;
> }
> 
> Same for xid.
> 
Yes, there would be better, will do that.

Thanks,
Tao



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-15 13:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-20 11:07 [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref Hou Tao
2018-12-09  6:34 ` Hou Tao
2018-12-09  6:52 ` Boris Brezillon
2018-12-13 21:53   ` Richard Weinberger
2018-12-15 13:17     ` Hou Tao

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).