Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8329571rwb; Tue, 13 Dec 2022 05:14:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6R3PVmPQcpV4azDXBbyahGj/TVYyUAkrlVng3oyA7UZupeWjOala9rpHJZO2GXR65GCmk4 X-Received: by 2002:a17:90a:f485:b0:212:cc3b:75f with SMTP id bx5-20020a17090af48500b00212cc3b075fmr21011996pjb.17.1670937250840; Tue, 13 Dec 2022 05:14:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670937250; cv=none; d=google.com; s=arc-20160816; b=HaNlEEnx4g07vFRkC7Qg8Ym8eyQ/hpe45jvK7EfF0tKiAPwb0wxUq02uRaqNsMUbxo JvS7wR2IyR6aLESGEzxTqXJEOWhfShgO4tKxt6MfpUVshZhV4DssI4Tuc1EgKVvN409F 9XmmsjXfu/7mZHm3P53s1odfFmrU9RNjM5WyFYQ6HV2UrwwK8B8OqXn5r8BQZ4VGTBav FxVX8tl/LyK4bZbJtNSdfVAy9iCzPgUkn+sRJczNEtOwuUr/EtGoLlW2y84jlTlIG8Rv xXn2kd1JEzu4FMGSbsDL69SF4KH+g5Djl1HrOl55aVR41YGidLS2dz4dWsDZSqrVKA6j zM4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=liOBmZ1DNzpLIjnVa/xImEt9qsglQFqsSIruVBxwnDM=; b=PzILYmx5Bd/gdvqtT3/hDARPMdG/Oh/G7zXK/bDIiELA0tpStDak1LDfIa7QHeQyqZ BwSJ0j3fudvdXwUdsj91kYHxV0VB0LE0GEVnkbG38zoLYkO13JVXykX/Exkf5qKlKRhN ip1q/l05AHTqPbRDywQv8zC6sPJMjCothkPy2a4moTEWYuHqkUkRCGS0KlRWod0nMj92 X7QMfSYiaAfMWXfchDDva+Um9dNkT+GSW8DrwszC1L1dkQO62Xvly9PAu0eJh3JhQ0CF 2h7b+DCreC7h8n29WqoAiWq3h9vZJQ5HNedcLC5X4pqX24lJT1qB4dTNgMTimP8l/8fC Jfew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=evzGVJCn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v202-20020a6361d3000000b0047916dd7d9asi11971382pgb.841.2022.12.13.05.14.00; Tue, 13 Dec 2022 05:14:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=evzGVJCn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235429AbiLMNEY (ORCPT + 74 others); Tue, 13 Dec 2022 08:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234940AbiLMNET (ORCPT ); Tue, 13 Dec 2022 08:04:19 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319E11D333; Tue, 13 Dec 2022 05:04:18 -0800 (PST) Received: from [192.168.10.9] (unknown [39.45.25.143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9F4BD6602BE3; Tue, 13 Dec 2022 13:04:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1670936655; bh=DS1yA+9XmvYzYNCforotpq+Ol0Tx/1wHHkNgJvMknJw=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=evzGVJCnpg4Ir/+WqpNCzOcMVx6xdKFUa4HxK6tKwytXZs8UBlg/7Wto83ls+GnYU zEdZHrxsd717cqCl5ylOk2uwbNbNQC/14rcXw86eVcjWPOlOPVSe44c7NdPhOOwX31 tOzXdmwu0QGuOtaB/RoRJs2OzDyLo79VXLFMJcm4/SnCYcxVXeT3QSxKCsEE0RrbFO HSgsGh+cfdTAv5HiH5Lq1zF4m+//KmonD/cqBokq/5WhmPPv64yiCHriPk44pw9la9 ukiD0t0DbNAOyFnmVan/cfDBl0ht7zKWOyqH0P6y3PVCmGqaFvfPIl5oyPevMlz3ou TbscPsB/9K+dg== Message-ID: Date: Tue, 13 Dec 2022 18:04:04 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Cc: Muhammad Usama Anjum , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin , Danylo Mocherniuk , Alexander Viro , Andrew Morton , Suren Baghdasaryan , Greg KH , Christian Brauner , Peter Xu , Yang Shi , Vlastimil Babka , Zach O'Keefe , "Matthew Wilcox (Oracle)" , "Gustavo A. R. Silva" , Dan Williams , kernel@collabora.com, Gabriel Krisman Bertazi , David Hildenbrand , Peter Enderborg , "open list : KERNEL SELFTEST FRAMEWORK" , Shuah Khan , open list , "open list : PROC FILESYSTEM" , "open list : MEMORY MANAGEMENT" , Paul Gofman Subject: Re: [PATCH v6 2/3] fs/proc/task_mmu: Implement IOCTL to get and/or the clear info about PTEs Content-Language: en-US To: Cyrill Gorcunov References: <20221109102303.851281-1-usama.anjum@collabora.com> <20221109102303.851281-3-usama.anjum@collabora.com> From: Muhammad Usama Anjum In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/13/22 1:42 AM, Cyrill Gorcunov wrote: > On Wed, Nov 09, 2022 at 03:23:02PM +0500, Muhammad Usama Anjum wrote: > ... >> + >> +static long do_pagemap_sd_cmd(struct mm_struct *mm, struct pagemap_scan_arg *arg) >> +{ >> + struct mmu_notifier_range range; >> + unsigned long __user start, end; >> + struct pagemap_scan_private p; >> + int ret; >> + >> + start = (unsigned long)untagged_addr(arg->start); >> + if ((!IS_ALIGNED(start, PAGE_SIZE)) || (!access_ok((void __user *)start, arg->len))) >> + return -EINVAL; >> + >> + if (IS_GET_OP(arg) && >> + ((arg->vec_len == 0) || (!access_ok((struct page_region *)arg->vec, arg->vec_len)))) >> + return -ENOMEM; >> + >> + if (IS_SD_OP(arg) && ((arg->required_mask & PAGEMAP_NONSD_OP_MASK) || >> + (arg->anyof_mask & PAGEMAP_NONSD_OP_MASK))) >> + return -EINVAL; >> + >> + end = start + arg->len; >> + p.max_pages = arg->max_pages; >> + p.found_pages = 0; >> + p.flags = arg->flags; >> + p.required_mask = arg->required_mask; >> + p.anyof_mask = arg->anyof_mask; >> + p.excluded_mask = arg->excluded_mask; >> + p.return_mask = arg->return_mask; >> + p.vec_index = 0; >> + p.vec_len = arg->vec_len; >> + >> + if (IS_GET_OP(arg)) { >> + p.vec = vzalloc(arg->vec_len * sizeof(struct page_region)); >> + if (!p.vec) >> + return -ENOMEM; >> + } else { >> + p.vec = NULL; >> + } > > Hi Muhammad! I'm really sorry for diving in such late (unfortunatelly too busy to > step in yet). Anyway, while in general such interface looks reasonable here are > few moments which really bothers me: as far as I undertstand you don't need > vzalloc here, plain vmalloc should works as well since you copy only filled > results back to userspace. Thank you for reviewing. Correct, I'll update to use vmalloc. > Next -- there is no restriction on vec_len parameter, > is not here a door for DoS from userspace? Say I could start a number of ioctl > on same pagemap and try to allocate very big amount of vec_len in summay causing > big pressure on kernel's memory. Or I miss something obvious here? Yes, there is a chance that a large chunk of kernel memory can get allocated here as vec_len can be very large. We need to think of limiting this buffer in the current implementation. Any reasonable limit should work. I'm not sure what would be the reasonable limit. Maybe couple of hundred MBs? I'll think about it. Or I should update the implementation such that less amount of intermediate buffer can be used like mincore does. But this can complicate the implementation further as we are already using page ranges instead of keeping just the flags. I'll see what can be done. -- BR, Muhammad Usama Anjum