Skip to contentSkip to conversation

fs/xfs/xfs_vnodeops.c:xfs_readdir(): NULL variable dereferenced

DISCUSSION Adrian Bunk 4 participants 5 messages Jul 6, 2006 – Jul 9, 2006

lore
Share & tools
lore
#0 lore raw

The Coverity checker spotted the following:

<-- snip -->

...
STATIC int
xfs_readdir(

        bhv_desc_t      *dir_bdp,
        uio_t           *uiop,
        cred_t          *credp,
        int             *eofp)
{
        xfs_inode_t     *dp;
        xfs_trans_t     *tp = NULL;
        int             error = 0;
        uint            lock_mode;

        vn_trace_entry(BHV_TO_VNODE(dir_bdp), __FUNCTION__,
                                               (inst_t *)__return_address);
        dp = XFS_BHVTOI(dir_bdp);

        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);

        lock_mode = xfs_ilock_map_shared(dp);
        error = xfs_dir_getdents(tp, dp, uiop, eofp);
        xfs_iunlock_map_shared(dp, lock_mode);
        return error;
}

...

<-- snip -->

Note that tp is never assigned any value other than NULL (and the Coverity checker found a way how tp might be dereferenced four function calls later).

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#1 lore raw
Quoted 29 lines · Adrian Bunk

The Coverity checker spotted the following:

<-- snip -->

...
STATIC int
xfs_readdir(

        bhv_desc_t      *dir_bdp,
        uio_t           *uiop,
        cred_t          *credp,
        int             *eofp)
{
        xfs_inode_t     *dp;
        xfs_trans_t     *tp = NULL;
        int             error = 0;
        uint            lock_mode;

        vn_trace_entry(BHV_TO_VNODE(dir_bdp), __FUNCTION__,
                                               (inst_t *)__return_address);
        dp = XFS_BHVTOI(dir_bdp);

        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);

        lock_mode = xfs_ilock_map_shared(dp);
        error = xfs_dir_getdents(tp, dp, uiop, eofp);
        xfs_iunlock_map_shared(dp, lock_mode);
        return error;
}
Quoted 7 lines

...

<-- snip -->

Note that tp is never assigned any value other than NULL (and the Coverity checker found a way how tp might be dereferenced four function calls later).

Then the bug is probably in the function call that uses tp without first checking whether it's null. Can you tell us where that dereference occurs?

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#2 lore raw
Quoted 6 lines
Quoted 5 lines

<-- snip -->

Note that tp is never assigned any value other than NULL (and the Coverity checker found a way how tp might be dereferenced four function calls later).

Quoted 7 lines

Then the bug is probably in the function call that uses tp without first checking whether it's null. Can you tell us where that dereference occurs?

Cheers,

Dave.

Maybe, but the above code is confusing too.

Why not get rid of tp and explicitly pass NULL as "xfs_dir_getdents(NULL, dp, uiop, eofp);"?

Hua

#3 lore raw
In reply to David Chinner
Quoted 34 lines · David Chinner
Quoted 33 lines · Adrian Bunk

The Coverity checker spotted the following:

<-- snip -->

...
STATIC int
xfs_readdir(

        bhv_desc_t      *dir_bdp,
        uio_t           *uiop,
        cred_t          *credp,
        int             *eofp)
{
        xfs_inode_t     *dp;
        xfs_trans_t     *tp = NULL;
        int             error = 0;
        uint            lock_mode;

        vn_trace_entry(BHV_TO_VNODE(dir_bdp), __FUNCTION__,
                                               (inst_t *)__return_address);
        dp = XFS_BHVTOI(dir_bdp);

        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);

        lock_mode = xfs_ilock_map_shared(dp);
        error = xfs_dir_getdents(tp, dp, uiop, eofp);
        xfs_iunlock_map_shared(dp, lock_mode);
        return error;
}

...

<-- snip -->

Quoted 7 lines
Quoted 3 lines

Note that tp is never assigned any value other than NULL (and the Coverity checker found a way how tp might be dereferenced four function calls later).

Then the bug is probably in the function call that uses tp without first checking whether it's null. Can you tell us where that dereference occurs?

xfs_readdir()
xfs_dir_getdents()

    xfs_dir2_leaf_getdents()
      xfs_bmapi()
        xfs_trans_log_inode()
          tp->t_flags |= XFS_TRANS_DIRTY;
Quoted 3 lines

Cheers,

Dave.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#4 lore raw
Quoted 3 lines · Adrian Bunk
Quoted 2 lines · David Chinner
Quoted 2 lines

Coverity checker found a way how tp might be dereferenced four function calls later).

Keyword being "might". ;)

Quoted 10 lines
Quoted 3 lines

Then the bug is probably in the function call that uses tp without first checking whether it's null. Can you tell us where that dereference occurs?

xfs_readdir()
xfs_dir_getdents()

    xfs_dir2_leaf_getdents()
      xfs_bmapi()
        xfs_trans_log_inode()
          tp->t_flags |= XFS_TRANS_DIRTY;

This actually cant happen due to the flags passed into xfs_bmapi (ie. request for a extent map _read_, which wont result in the inode being logged, which means no transaction dirtying).

That suggestion to remove the local "tp" variable was valid though, we may as well do that (will do).

cheers.

Signature · 1 line
Nathan