2012-08-23 10:49:23

by Cyrill Gorcunov

[permalink] [raw]
Subject: [patch 4/9] fs, exportfs: Fix nil dereference if no s_export_op present

If there is no s_export_op present in a target superblock
we might have nil dereference. Fix it with eplicit test
if s_export_op is provided.

Signed-off-by: Cyrill Gorcunov <[email protected]>
CC: Pavel Emelyanov <[email protected]>
CC: Al Viro <[email protected]>
CC: Alexey Dobriyan <[email protected]>
CC: Andrew Morton <[email protected]>
CC: James Bottomley <[email protected]>
CC: "Aneesh Kumar K.V" <[email protected]>
CC: Alexey Dobriyan <[email protected]>
CC: Matthew Helsley <[email protected]>
CC: "J. Bruce Fields" <[email protected]>
CC: "Aneesh Kumar K.V" <[email protected]>
---
fs/exportfs/expfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.git/fs/exportfs/expfs.c
===================================================================
--- linux-2.6.git.orig/fs/exportfs/expfs.c
+++ linux-2.6.git/fs/exportfs/expfs.c
@@ -357,7 +357,7 @@ int exportfs_encode_fh(struct dentry *de
*/
parent = p->d_inode;
}
- if (nop->encode_fh)
+ if (nop && nop->encode_fh)
error = nop->encode_fh(inode, fid->raw, max_len, parent);
else
error = export_encode_fh(inode, fid, max_len, parent);


2012-08-23 12:12:37

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 4/9] fs, exportfs: Fix nil dereference if no s_export_op present

On Thu, Aug 23, 2012 at 02:43:27PM +0400, Cyrill Gorcunov wrote:
> If there is no s_export_op present in a target superblock
> we might have nil dereference.

Is that NULL dereference possible with current code, or is it a check
you're adding to account for a new caller that you're about to add?

I believe it's the latter, but this would be a good thing to make clear
in the changelog.

--b.

> Fix it with eplicit test
> if s_export_op is provided.
>
> Signed-off-by: Cyrill Gorcunov <[email protected]>
> CC: Pavel Emelyanov <[email protected]>
> CC: Al Viro <[email protected]>
> CC: Alexey Dobriyan <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: James Bottomley <[email protected]>
> CC: "Aneesh Kumar K.V" <[email protected]>
> CC: Alexey Dobriyan <[email protected]>
> CC: Matthew Helsley <[email protected]>
> CC: "J. Bruce Fields" <[email protected]>
> CC: "Aneesh Kumar K.V" <[email protected]>
> ---
> fs/exportfs/expfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux-2.6.git/fs/exportfs/expfs.c
> ===================================================================
> --- linux-2.6.git.orig/fs/exportfs/expfs.c
> +++ linux-2.6.git/fs/exportfs/expfs.c
> @@ -357,7 +357,7 @@ int exportfs_encode_fh(struct dentry *de
> */
> parent = p->d_inode;
> }
> - if (nop->encode_fh)
> + if (nop && nop->encode_fh)
> error = nop->encode_fh(inode, fid->raw, max_len, parent);
> else
> error = export_encode_fh(inode, fid, max_len, parent);
>

2012-08-23 12:34:29

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [patch 4/9] fs, exportfs: Fix nil dereference if no s_export_op present

On Thu, Aug 23, 2012 at 08:12:30AM -0400, J. Bruce Fields wrote:
> On Thu, Aug 23, 2012 at 02:43:27PM +0400, Cyrill Gorcunov wrote:
> > If there is no s_export_op present in a target superblock
> > we might have nil dereference.
>
> Is that NULL dereference possible with current code, or is it a check
> you're adding to account for a new caller that you're about to add?
>
> I believe it's the latter, but this would be a good thing to make clear
> in the changelog.

With the current code it seems to be impossible (well, i can't be sure
about nfs caller) because do_sys_name_to_handle does check for s_export_op
to exist. Updated changelog below. After all I think not checking
s_export_op was a mistake in general -- this routine is exported to
other modules but has no a single line of comment about possibility
of nil dereference.
---
From: Cyrill Gorcunov <[email protected]>
Subject: fs, exportfs: Escape nil dereference if no s_export_op present

This routine will be used to generate a file handle in fdinfo
output for inotify subsystem, where if no s_export_op present
the general export_encode_fh should be used. Thus add
a test if s_export_op present inside exportfs_encode_fh itself.

Signed-off-by: Cyrill Gorcunov <[email protected]>
CC: Pavel Emelyanov <[email protected]>
CC: Al Viro <[email protected]>
CC: Alexey Dobriyan <[email protected]>
CC: Andrew Morton <[email protected]>
CC: James Bottomley <[email protected]>
CC: "Aneesh Kumar K.V" <[email protected]>
CC: Alexey Dobriyan <[email protected]>
CC: Matthew Helsley <[email protected]>
CC: "J. Bruce Fields" <[email protected]>
CC: "Aneesh Kumar K.V" <[email protected]>
---
fs/exportfs/expfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.git/fs/exportfs/expfs.c
===================================================================
--- linux-2.6.git.orig/fs/exportfs/expfs.c
+++ linux-2.6.git/fs/exportfs/expfs.c
@@ -357,7 +357,7 @@ int exportfs_encode_fh(struct dentry *de
*/
parent = p->d_inode;
}
- if (nop->encode_fh)
+ if (nop && nop->encode_fh)
error = nop->encode_fh(inode, fid->raw, max_len, parent);
else
error = export_encode_fh(inode, fid, max_len, parent);

2012-08-23 15:22:13

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [patch 4/9] fs, exportfs: Fix nil dereference if no s_export_op present

On Thu, Aug 23, 2012 at 04:34:22PM +0400, Cyrill Gorcunov wrote:
> On Thu, Aug 23, 2012 at 08:12:30AM -0400, J. Bruce Fields wrote:
> > On Thu, Aug 23, 2012 at 02:43:27PM +0400, Cyrill Gorcunov wrote:
> > > If there is no s_export_op present in a target superblock
> > > we might have nil dereference.
> >
> > Is that NULL dereference possible with current code, or is it a check
> > you're adding to account for a new caller that you're about to add?
> >
> > I believe it's the latter, but this would be a good thing to make clear
> > in the changelog.
>
> With the current code it seems to be impossible (well, i can't be sure
> about nfs caller) because do_sys_name_to_handle does check for s_export_op
> to exist. Updated changelog below. After all I think not checking
> s_export_op was a mistake in general -- this routine is exported to
> other modules but has no a single line of comment about possibility
> of nil dereference.

Fine, just make sure that's explained in the changelog.

For distributors looking for patches to backport, "fix nil dereference"
may set off alarm bells unnecessarily.

--b.

> ---
> From: Cyrill Gorcunov <[email protected]>
> Subject: fs, exportfs: Escape nil dereference if no s_export_op present
>
> This routine will be used to generate a file handle in fdinfo
> output for inotify subsystem, where if no s_export_op present
> the general export_encode_fh should be used. Thus add
> a test if s_export_op present inside exportfs_encode_fh itself.
>
> Signed-off-by: Cyrill Gorcunov <[email protected]>
> CC: Pavel Emelyanov <[email protected]>
> CC: Al Viro <[email protected]>
> CC: Alexey Dobriyan <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: James Bottomley <[email protected]>
> CC: "Aneesh Kumar K.V" <[email protected]>
> CC: Alexey Dobriyan <[email protected]>
> CC: Matthew Helsley <[email protected]>
> CC: "J. Bruce Fields" <[email protected]>
> CC: "Aneesh Kumar K.V" <[email protected]>
> ---
> fs/exportfs/expfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux-2.6.git/fs/exportfs/expfs.c
> ===================================================================
> --- linux-2.6.git.orig/fs/exportfs/expfs.c
> +++ linux-2.6.git/fs/exportfs/expfs.c
> @@ -357,7 +357,7 @@ int exportfs_encode_fh(struct dentry *de
> */
> parent = p->d_inode;
> }
> - if (nop->encode_fh)
> + if (nop && nop->encode_fh)
> error = nop->encode_fh(inode, fid->raw, max_len, parent);
> else
> error = export_encode_fh(inode, fid, max_len, parent);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html