diff options
author | Elena Reshetova <elena.reshetova@intel.com> | 2017-10-20 05:53:38 -0400 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2017-11-17 13:48:01 -0500 |
commit | 212bf41d88c06afc23e03f9b274eebf1e8dba197 (patch) | |
tree | 755a58e9b423e6e8bfe06fa2036b633a427ff42b /fs/nfs/filelayout/filelayout.c | |
parent | 2f62b5aa4814be2c511553fd6afb4d35b6c2503b (diff) |
fs, nfs: convert nfs_client.cl_count from atomic_t to refcount_t
atomic_t variables are currently used to implement reference
counters with the following properties:
- counter is initialized to 1 using atomic_set()
- a resource is freed upon counter reaching zero
- once counter reaches zero, its further
increments aren't allowed
- counter schema uses basic atomic operations
(set, inc, inc_not_zero, dec_and_test, etc.)
Such atomic variables should be converted to a newly provided
refcount_t type and API that prevents accidental counter overflows
and underflows. This is important since overflows and underflows
can lead to use-after-free situation and be exploitable.
The variable nfs_client.cl_count is used as pure reference counter.
Convert it to refcount_t and fix up the operations.
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs/filelayout/filelayout.c')
-rw-r--r-- | fs/nfs/filelayout/filelayout.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c index 508126eb49f9..4e54d8b5413a 100644 --- a/fs/nfs/filelayout/filelayout.c +++ b/fs/nfs/filelayout/filelayout.c | |||
@@ -471,10 +471,10 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr) | |||
471 | return PNFS_NOT_ATTEMPTED; | 471 | return PNFS_NOT_ATTEMPTED; |
472 | 472 | ||
473 | dprintk("%s USE DS: %s cl_count %d\n", __func__, | 473 | dprintk("%s USE DS: %s cl_count %d\n", __func__, |
474 | ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count)); | 474 | ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count)); |
475 | 475 | ||
476 | /* No multipath support. Use first DS */ | 476 | /* No multipath support. Use first DS */ |
477 | atomic_inc(&ds->ds_clp->cl_count); | 477 | refcount_inc(&ds->ds_clp->cl_count); |
478 | hdr->ds_clp = ds->ds_clp; | 478 | hdr->ds_clp = ds->ds_clp; |
479 | hdr->ds_commit_idx = idx; | 479 | hdr->ds_commit_idx = idx; |
480 | fh = nfs4_fl_select_ds_fh(lseg, j); | 480 | fh = nfs4_fl_select_ds_fh(lseg, j); |
@@ -515,10 +515,10 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync) | |||
515 | 515 | ||
516 | dprintk("%s ino %lu sync %d req %zu@%llu DS: %s cl_count %d\n", | 516 | dprintk("%s ino %lu sync %d req %zu@%llu DS: %s cl_count %d\n", |
517 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count, | 517 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count, |
518 | offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count)); | 518 | offset, ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count)); |
519 | 519 | ||
520 | hdr->pgio_done_cb = filelayout_write_done_cb; | 520 | hdr->pgio_done_cb = filelayout_write_done_cb; |
521 | atomic_inc(&ds->ds_clp->cl_count); | 521 | refcount_inc(&ds->ds_clp->cl_count); |
522 | hdr->ds_clp = ds->ds_clp; | 522 | hdr->ds_clp = ds->ds_clp; |
523 | hdr->ds_commit_idx = idx; | 523 | hdr->ds_commit_idx = idx; |
524 | fh = nfs4_fl_select_ds_fh(lseg, j); | 524 | fh = nfs4_fl_select_ds_fh(lseg, j); |
@@ -1064,9 +1064,9 @@ static int filelayout_initiate_commit(struct nfs_commit_data *data, int how) | |||
1064 | goto out_err; | 1064 | goto out_err; |
1065 | 1065 | ||
1066 | dprintk("%s ino %lu, how %d cl_count %d\n", __func__, | 1066 | dprintk("%s ino %lu, how %d cl_count %d\n", __func__, |
1067 | data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count)); | 1067 | data->inode->i_ino, how, refcount_read(&ds->ds_clp->cl_count)); |
1068 | data->commit_done_cb = filelayout_commit_done_cb; | 1068 | data->commit_done_cb = filelayout_commit_done_cb; |
1069 | atomic_inc(&ds->ds_clp->cl_count); | 1069 | refcount_inc(&ds->ds_clp->cl_count); |
1070 | data->ds_clp = ds->ds_clp; | 1070 | data->ds_clp = ds->ds_clp; |
1071 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); | 1071 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); |
1072 | if (fh) | 1072 | if (fh) |