Skip to contentSkip to conversation

dax: explain how read(2)/write(2) addresses are validated

PATCH Applied Ross Zwisler 2 participants 3 messages Aug 16, 2017 – Aug 17, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CAGXu5jJqoegDg07vR0iRRV1U_qOpZx5eLbywEwD_sm-D7sQmdA@mail.gmail.com

#1 lore raw

PATCH 1/1 dax: explain how read(2)/write(2) addresses are validated

Add a comment explaining how the user addresses provided to read(2) and write(2) are validated in the DAX I/O path. We call dax_copy_from_iter() or copy_to_iter() on these without calling access_ok() first in the DAX code, and there was a concern that the user might be able to read/write to arbitrary kernel addresses with this path.

---

Adding a comment instead of adding redundant access_ok() calls in the DAX code. If this is the wrong path to take, please let me know.

 fs/dax.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/dax.c +5 -0
index 8c67517..2d50f32 100644
@@ -1060,6 +1060,11 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 		if (map_len > end - pos)
 			map_len = end - pos;
 
+		/*
+		 * The userspace address for the memory copy has already been
+		 * validated via access_ok() in either vfs_read() or
+		 * vfs_write(), depending on which operation we are doing.
+		 */
 		if (iov_iter_rw(iter) == WRITE)
 			map_len = dax_copy_from_iter(dax_dev, pgoff, kaddr,
 					map_len, iter);
Signature · 6 lines
2.9.5

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 7 lines · Ross Zwisler

Add a comment explaining how the user addresses provided to read(2) and write(2) are validated in the DAX I/O path. We call dax_copy_from_iter() or copy_to_iter() on these without calling access_ok() first in the DAX code, and there was a concern that the user might be able to read/write to arbitrary kernel addresses with this path.

Looks OK to me so feel free to add:

Just I'd note that standard buffered read / write path is no different so I don't see a big point in adding this comment when it is not in any other path either...

Honza

Quoted 27 lines

---

Adding a comment instead of adding redundant access_ok() calls in the DAX code. If this is the wrong path to take, please let me know.

 fs/dax.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/dax.c +5 -0
index 8c67517..2d50f32 100644
@@ -1060,6 +1060,11 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 		if (map_len > end - pos)
 			map_len = end - pos;
 
+		/*
+		 * The userspace address for the memory copy has already been
+		 * validated via access_ok() in either vfs_read() or
+		 * vfs_write(), depending on which operation we are doing.
+		 */
 		if (iov_iter_rw(iter) == WRITE)
 			map_len = dax_copy_from_iter(dax_dev, pgoff, kaddr,
 					map_len, iter);
Signature · 1 line
2.9.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw
Quoted 9 lines · Jan Kara
Quoted 7 lines · Ross Zwisler

Add a comment explaining how the user addresses provided to read(2) and write(2) are validated in the DAX I/O path. We call dax_copy_from_iter() or copy_to_iter() on these without calling access_ok() first in the DAX code, and there was a concern that the user might be able to read/write to arbitrary kernel addresses with this path.

Quoted 7 lines

Looks OK to me so feel free to add:

Just I'd note that standard buffered read / write path is no different so I don't see a big point in adding this comment when it is not in any other path either...

Fair enough. Yea, if it's not in any of the other paths either and it's just common knowledge that these addresses are validated at the VFS layer, we can leave it out.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm