From patchwork Tue Aug 15 14:43:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 9901973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 67ED960230 for ; Tue, 15 Aug 2017 14:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B16628867 for ; Tue, 15 Aug 2017 14:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FCD32888D; Tue, 15 Aug 2017 14:44:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F55028867 for ; Tue, 15 Aug 2017 14:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752510AbdHOOoe (ORCPT ); Tue, 15 Aug 2017 10:44:34 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41443 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752499AbdHOOod (ORCPT ); Tue, 15 Aug 2017 10:44:33 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7FEh4dQ146384 for ; Tue, 15 Aug 2017 10:44:33 -0400 Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cbvj3293t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 15 Aug 2017 10:44:32 -0400 Received: from localhost by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Aug 2017 00:44:30 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 16 Aug 2017 00:44:27 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7FEiRhZ40042596; Wed, 16 Aug 2017 00:44:27 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7FEiQk9022000; Wed, 16 Aug 2017 00:44:27 +1000 Received: from localhost.localdomain.com ([9.80.85.193]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7FEiIia021776; Wed, 16 Aug 2017 00:44:23 +1000 From: Mimi Zohar To: Christoph Hellwig , Al Viro Cc: Matthew Garrett , Mimi Zohar , James Morris , linux-fsdevel@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, Matthew Garrett Subject: [PATCH v6 1/6] libfs: define simple_read_iter_from_buffer Date: Tue, 15 Aug 2017 10:43:52 -0400 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502808237-2035-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1502808237-2035-1-git-send-email-zohar@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17081514-0044-0000-0000-000002825F9A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17081514-0045-0000-0000-000007156BD6 Message-Id: <1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-15_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708150247 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Christoph Hellwig --- 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);