Should iov_iter_get_pages*() be EXPORT_SYMBOL_GPL?

From: David Howells
Date: Wed Nov 23 2022 - 08:47:32 EST


I recently posted an intended replacement[1] for iov_iter_get_pages*() which,
instead of always just getting a ref on the pages it extracts from the
iterator it is given, will pin them or leave them unaltered (but still in the
list) as appropriate.

However, Christoph objected[2] to my using EXPORT_SYMBOL() with it on the
basis that:

get_user_pages_fast, pin_user_pages_fast are very intentionally
EXPORT_SYMBOL_GPL, which should not be bypassed by an iov_* wrapper.

but iov_iter_get_pages*() is EXPORT_SYMBOL(), so it's already possible to
bypass this restriction. He has also raised other objections[3].

Should we then convert this to EXPORT_SYMBOL_GPL(), as per the attached patch?

Link: https://lore.kernel.org/r/166920902005.1461876.2786264600108839814.stgit@xxxxxxxxxxxxxxxxxxxxxx/ [1]
Link: https://lore.kernel.org/r/Y3zFzdWnWlEJ8X8/@infradead.org/ [2]
Link: https://lore.kernel.org/lkml/20221025154143.GA25128@xxxxxx/ [3]
---
iov_iter: Mark iov_iter_get_pages2*() as EXPORT_SYMBOL_GPL()

iov_iter_get_pages2*() should be marked EXPORT_SYMBOL_GPL() as the use
get_user_pages_fast()[1].

Reported-by: Christoph Hellwig <hch@xxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
cc: linux-mm@xxxxxxxxx
cc: linux-fsdevel@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/Y3zFzdWnWlEJ8X8/@infradead.org/ [1]
---
iov_iter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 612fc9bf9881..02b02a5fece4 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1502,7 +1502,7 @@ ssize_t iov_iter_get_pages2(struct iov_iter *i,

return __iov_iter_get_pages_alloc(i, &pages, maxsize, maxpages, start);
}
-EXPORT_SYMBOL(iov_iter_get_pages2);
+EXPORT_SYMBOL_GPL(iov_iter_get_pages2);

ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i,
struct page ***pages, size_t maxsize,
@@ -1519,7 +1519,7 @@ ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i,
}
return len;
}
-EXPORT_SYMBOL(iov_iter_get_pages_alloc2);
+EXPORT_SYMBOL_GPL(iov_iter_get_pages_alloc2);

size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum,
struct iov_iter *i)