Re: [v4 PATCH 5/6] mm: shmem: don't truncate page if memory failure happens

From: Naoya Horiguchi
Date: Tue Oct 19 2021 - 18:30:22 EST


On Tue, Oct 19, 2021 at 10:29:51AM -0700, Yang Shi wrote:
> On Mon, Oct 18, 2021 at 10:52 PM Naoya Horiguchi
> <naoya.horiguchi@xxxxxxxxx> wrote:
> >
> > On Thu, Oct 14, 2021 at 12:16:14PM -0700, Yang Shi wrote:
...
> > > @@ -2466,7 +2467,15 @@ shmem_write_begin(struct file *file, struct address_space *mapping,
> > > return -EPERM;
> > > }
> > >
> > > - return shmem_getpage(inode, index, pagep, SGP_WRITE);
> > > + ret = shmem_getpage(inode, index, pagep, SGP_WRITE);
> > > +
> > > + if (*pagep && PageHWPoison(*pagep)) {
> >
> > shmem_getpage() could return with pagep == NULL, so you need check ret first
> > to avoid NULL pointer dereference.
>
> Realy? IIUC pagep can't be NULL. It is a pointer's pointer passed in
> by the caller, for example, generic_perform_write(). Of course,
> "*pagep" could be NULL.

Oh, I simply missed this. You're right. Please ignore my comment on this.

- Naoya Horiguchi