From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from userp1040.oracle.com ([156.151.31.81]:40313 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756934AbcIODVT (ORCPT ); Wed, 14 Sep 2016 23:21:19 -0400 Date: Wed, 14 Sep 2016 20:20:44 -0700 From: "Darrick J. Wong" To: torvalds@linux-foundation.org Cc: Christoph Hellwig , david@fromorbit.com, viro@ZenIV.linux.org.uk, linux-xfs@vger.kernel.org, "Kirill A. Shutemov" , xfs@oss.sgi.com, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH] vfs: cap dedupe request structure size at PAGE_SIZE Message-ID: <20160915032044.GB9309@birch.djwong.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Kirill A. Shutemov reports that the kernel doesn't try to cap dest_count in any way, and uses the number to allocate kernel memory. This causes high order allocation warnings in the kernel log if someone passes in a big enough value. We should clamp the allocation at PAGE_SIZE to avoid stressing the VM. The two existing users of the dedupe ioctl never send more than 120 requests, so we can safely clamp dest_range at PAGE_SIZE, because with 4k pages we can handle up to 127 dedupe candidates. Given the max extent length of 16MB, we can end up doing 2GB of IO which is plenty. Reported-by: "Kirill A. Shutemov" Signed-off-by: Darrick J. Wong --- fs/ioctl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/ioctl.c b/fs/ioctl.c index 26aba09..c415668 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -582,6 +582,10 @@ static int ioctl_file_dedupe_range(struct file *file, void __user *arg) } size = offsetof(struct file_dedupe_range __user, info[count]); + if (size > PAGE_SIZE) { + ret = -ENOMEM; + goto out; + } same = memdup_user(argp, size); if (IS_ERR(same)) {