* [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them
@ 2018-06-28 9:28 Carlos Maiolino
2018-06-28 11:42 ` Brian Foster
2018-06-28 13:56 ` Darrick J. Wong
0 siblings, 2 replies; 3+ messages in thread
From: Carlos Maiolino @ 2018-06-28 9:28 UTC (permalink / raw)
To: linux-xfs
Make sure we initialize *bno and *len, before jumping to out_bad_rec
label, and risk calling xfs_warn() with uninitialized variables.
Coverity: 100898
Coverity: 1437081
Coverity: 1437129
Coverity: 1437191
Coverity: 1437201
Coverity: 1437212
Coverity: 1437341
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
This is based on Darrick's suggestion, although, I believe initializing *bno and
*len before testing if *len is empty or not is a bit more clear than changing
xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount
directly.
fs/xfs/libxfs/xfs_alloc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index eef466260d43..75dbdc14c45f 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -223,12 +223,13 @@ xfs_alloc_get_rec(
error = xfs_btree_get_rec(cur, &rec, stat);
if (error || !(*stat))
return error;
- if (rec->alloc.ar_blockcount == 0)
- goto out_bad_rec;
*bno = be32_to_cpu(rec->alloc.ar_startblock);
*len = be32_to_cpu(rec->alloc.ar_blockcount);
+ if (*len == 0)
+ goto out_bad_rec;
+
/* check for valid extent range, including overflow */
if (!xfs_verify_agbno(mp, agno, *bno))
goto out_bad_rec;
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them
2018-06-28 9:28 [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them Carlos Maiolino
@ 2018-06-28 11:42 ` Brian Foster
2018-06-28 13:56 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Brian Foster @ 2018-06-28 11:42 UTC (permalink / raw)
To: Carlos Maiolino; +Cc: linux-xfs
On Thu, Jun 28, 2018 at 11:28:35AM +0200, Carlos Maiolino wrote:
> Make sure we initialize *bno and *len, before jumping to out_bad_rec
> label, and risk calling xfs_warn() with uninitialized variables.
>
> Coverity: 100898
> Coverity: 1437081
> Coverity: 1437129
> Coverity: 1437191
> Coverity: 1437201
> Coverity: 1437212
> Coverity: 1437341
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
Reviewed-by: Brian Foster <bfoster@redhat.com>
>
> This is based on Darrick's suggestion, although, I believe initializing *bno and
> *len before testing if *len is empty or not is a bit more clear than changing
> xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount
> directly.
>
> fs/xfs/libxfs/xfs_alloc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index eef466260d43..75dbdc14c45f 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -223,12 +223,13 @@ xfs_alloc_get_rec(
> error = xfs_btree_get_rec(cur, &rec, stat);
> if (error || !(*stat))
> return error;
> - if (rec->alloc.ar_blockcount == 0)
> - goto out_bad_rec;
>
> *bno = be32_to_cpu(rec->alloc.ar_startblock);
> *len = be32_to_cpu(rec->alloc.ar_blockcount);
>
> + if (*len == 0)
> + goto out_bad_rec;
> +
> /* check for valid extent range, including overflow */
> if (!xfs_verify_agbno(mp, agno, *bno))
> goto out_bad_rec;
> --
> 2.14.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them
2018-06-28 9:28 [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them Carlos Maiolino
2018-06-28 11:42 ` Brian Foster
@ 2018-06-28 13:56 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2018-06-28 13:56 UTC (permalink / raw)
To: Carlos Maiolino; +Cc: linux-xfs
On Thu, Jun 28, 2018 at 11:28:35AM +0200, Carlos Maiolino wrote:
> Make sure we initialize *bno and *len, before jumping to out_bad_rec
> label, and risk calling xfs_warn() with uninitialized variables.
>
> Coverity: 100898
> Coverity: 1437081
> Coverity: 1437129
> Coverity: 1437191
> Coverity: 1437201
> Coverity: 1437212
> Coverity: 1437341
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
>
> This is based on Darrick's suggestion, although, I believe initializing *bno and
> *len before testing if *len is empty or not is a bit more clear than changing
> xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount
> directly.
>
> fs/xfs/libxfs/xfs_alloc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index eef466260d43..75dbdc14c45f 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -223,12 +223,13 @@ xfs_alloc_get_rec(
> error = xfs_btree_get_rec(cur, &rec, stat);
> if (error || !(*stat))
> return error;
> - if (rec->alloc.ar_blockcount == 0)
> - goto out_bad_rec;
>
> *bno = be32_to_cpu(rec->alloc.ar_startblock);
> *len = be32_to_cpu(rec->alloc.ar_blockcount);
>
> + if (*len == 0)
> + goto out_bad_rec;
> +
> /* check for valid extent range, including overflow */
> if (!xfs_verify_agbno(mp, agno, *bno))
> goto out_bad_rec;
> --
> 2.14.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-28 13:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-28 9:28 [PATCH V2] xfs: Initialize variables in xfs_alloc_get_rec before using them Carlos Maiolino
2018-06-28 11:42 ` Brian Foster
2018-06-28 13:56 ` Darrick J. Wong
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).