From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f67.google.com ([209.85.218.67]:38850 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932306AbdHVKEj (ORCPT ); Tue, 22 Aug 2017 06:04:39 -0400 MIME-Version: 1.0 In-Reply-To: <1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com> References: <1502808237-2035-1-git-send-email-zohar@linux.vnet.ibm.com> <1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com> From: Dmitry Kasatkin Date: Tue, 22 Aug 2017 13:04:37 +0300 Message-ID: Subject: Re: [PATCH v6 1/6] libfs: define simple_read_iter_from_buffer To: Mimi Zohar Cc: Christoph Hellwig , Al Viro , Matthew Garrett , James Morris , linux-fsdevel@vger.kernel.org, linux-ima-devel , linux-security-module , Matthew Garrett Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Looks good to me. On Tue, Aug 15, 2017 at 5:43 PM, Mimi Zohar wrote: > In preparation for defining an integrity_read file operation > method for efivarfs, define a simple_read_iter_from_buffer() > function. > > (Based on Al's code as posted in thread.) > > Suggested-by: Al Viro > Signed-off-by: Mimi Zohar > Cc: Matthew Garrett > > --- > Changelog v6: > - defined as a separate patch > > fs/libfs.c | 32 ++++++++++++++++++++++++++++++++ > include/linux/fs.h | 2 ++ > 2 files changed, 34 insertions(+) > > diff --git a/fs/libfs.c b/fs/libfs.c > index 3aabe553fc45..b6e304c6828b 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -16,6 +16,7 @@ > #include > #include > #include /* sync_mapping_buffers */ > +#include > > #include > > @@ -676,6 +677,37 @@ ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, > EXPORT_SYMBOL(simple_write_to_buffer); > > /** > + * simple_read_iter_from_buffer - copy data from the buffer to user space > + * @iocb: struct containing the file, the current position and other info > + * @to: the user space buffer to read to > + * @from: the buffer to read from > + * @available: the size of the buffer > + * > + * The simple_read_iter_from_buffer() function reads up to @available bytes > + * from the current buffer into the user space buffer. > + * > + * On success, the current buffer offset is advanced by the number of bytes > + * read, or a negative value is returned on error. > + **/ > +ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, struct iov_iter *to, > + const void *from, size_t available) > +{ > + loff_t pos = iocb->ki_pos; > + size_t ret; > + > + if (pos < 0) > + return -EINVAL; > + if (pos >= available) > + return 0; > + ret = copy_to_iter(from + pos, available - pos, to); > + if (!ret && iov_iter_count(to)) > + return -EFAULT; > + iocb->ki_pos = pos + ret; > + return ret; > +} > +EXPORT_SYMBOL(simple_read_iter_from_buffer); > + > +/** > * memory_read_from_buffer - copy data from the buffer > * @to: the kernel space buffer to read to > * @count: the maximum number of bytes to read > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 6e1fd5d21248..fdec9b763b54 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -3097,6 +3097,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count); > > extern ssize_t simple_read_from_buffer(void __user *to, size_t count, > loff_t *ppos, const void *from, size_t available); > +extern ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, > + struct iov_iter *to, const void *from, size_t available); > extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, > const void __user *from, size_t count); > > -- > 2.7.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-security-module" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Thanks, Dmitry From mboxrd@z Thu Jan 1 00:00:00 1970 From: dmitry.kasatkin@gmail.com (Dmitry Kasatkin) Date: Tue, 22 Aug 2017 13:04:37 +0300 Subject: [PATCH v6 1/6] libfs: define simple_read_iter_from_buffer In-Reply-To: <1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com> References: <1502808237-2035-1-git-send-email-zohar@linux.vnet.ibm.com> <1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com> Message-ID: To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org Looks good to me. On Tue, Aug 15, 2017 at 5:43 PM, Mimi Zohar wrote: > In preparation for defining an integrity_read file operation > method for efivarfs, define a simple_read_iter_from_buffer() > function. > > (Based on Al's code as posted in thread.) > > Suggested-by: Al Viro > Signed-off-by: Mimi Zohar > Cc: Matthew Garrett > > --- > Changelog v6: > - defined as a separate patch > > fs/libfs.c | 32 ++++++++++++++++++++++++++++++++ > include/linux/fs.h | 2 ++ > 2 files changed, 34 insertions(+) > > diff --git a/fs/libfs.c b/fs/libfs.c > index 3aabe553fc45..b6e304c6828b 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -16,6 +16,7 @@ > #include > #include > #include /* sync_mapping_buffers */ > +#include > > #include > > @@ -676,6 +677,37 @@ ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, > EXPORT_SYMBOL(simple_write_to_buffer); > > /** > + * simple_read_iter_from_buffer - copy data from the buffer to user space > + * @iocb: struct containing the file, the current position and other info > + * @to: the user space buffer to read to > + * @from: the buffer to read from > + * @available: the size of the buffer > + * > + * The simple_read_iter_from_buffer() function reads up to @available bytes > + * from the current buffer into the user space buffer. > + * > + * On success, the current buffer offset is advanced by the number of bytes > + * read, or a negative value is returned on error. > + **/ > +ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, struct iov_iter *to, > + const void *from, size_t available) > +{ > + loff_t pos = iocb->ki_pos; > + size_t ret; > + > + if (pos < 0) > + return -EINVAL; > + if (pos >= available) > + return 0; > + ret = copy_to_iter(from + pos, available - pos, to); > + if (!ret && iov_iter_count(to)) > + return -EFAULT; > + iocb->ki_pos = pos + ret; > + return ret; > +} > +EXPORT_SYMBOL(simple_read_iter_from_buffer); > + > +/** > * memory_read_from_buffer - copy data from the buffer > * @to: the kernel space buffer to read to > * @count: the maximum number of bytes to read > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 6e1fd5d21248..fdec9b763b54 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -3097,6 +3097,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count); > > extern ssize_t simple_read_from_buffer(void __user *to, size_t count, > loff_t *ppos, const void *from, size_t available); > +extern ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, > + struct iov_iter *to, const void *from, size_t available); > extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, > const void __user *from, size_t count); > > -- > 2.7.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-security-module" in > the body of a message to majordomo at vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Thanks, Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html