Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp37137ybi; Fri, 26 Jul 2019 05:47:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvPpYPVuj8D3AvJcKtIzo46B3XLljzWW1LcWv20i9oCIqXA7QuQfNKdSjI+FkLlHxs5TCx X-Received: by 2002:a63:c008:: with SMTP id h8mr89152973pgg.427.1564145239432; Fri, 26 Jul 2019 05:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564145239; cv=none; d=google.com; s=arc-20160816; b=1IrgJZRFw/XBF4tpUi22F7hWqF0MFUzb3Q/Auc8kOOnj5jLoxH69U11RMdKZviHac+ +8/AZ63djQ5IsYYtMU+PjlqagWNFIXwzCdbWCmYG0EpxsRZLOJvDwiflb+FyQMY5AynP foX+elOfWRflwtcG4v0VE7BP5KmP/GvF/M5sG2pxIJuMHE8ZFjmg6buOaAEABwVD3h5h B+9/99K9na73Y/1Mjta3irllKeX+DdBFW2CoXpXwN3alENCNVuoN1seESDDYw+kcNbjk AuEtCLaF5+qWJhSTfFHqV0FUWfCkkB+gWFhRdMGQ95FUI62hRP34EG3MSZDbZ/ArrfUe fmXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IIyzRbatR38ttllEYMMotwwVkanyqchmaJcpYBpIki0=; b=MO98j6qWjwPATlym5q6nTRlafNJLJlGQalnrnXFMjpVtIitmw7oQQL7vs74kznarvq lcYnE4vDKZNwpc/VgH2GqnFoelL3LvGzcEJ5yKyYwI9G7MIHtHvXEEuG3IarNWXA7t1q MBOaLrWFylWAmY+wrgMvdRmeSF7GfYLxGy1Ox0QP+Psofa0Pa2uygokgIAATP+UvrNbI rwiXQ1ZkIwIR88x1MI9sj6Cvv1OJZ7He+s58ZQBmjKsIYYekaUQdbCIpRz9cMAIrKgRI WjTV/q7n5kIbPk+F4j5JTWabxYvmD1VKu9VzHhtGty53ho/dgjymQuXEQPIY/HkS4N9G 3sUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=pETxnGiW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si18967087pgj.213.2019.07.26.05.47.03; Fri, 26 Jul 2019 05:47:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=pETxnGiW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726262AbfGZLpc (ORCPT + 99 others); Fri, 26 Jul 2019 07:45:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38451 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfGZLpb (ORCPT ); Fri, 26 Jul 2019 07:45:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id r9so51188139ljg.5 for ; Fri, 26 Jul 2019 04:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IIyzRbatR38ttllEYMMotwwVkanyqchmaJcpYBpIki0=; b=pETxnGiWkSphfi8/+4c4u+22brSho8PFLYphcLagT7bB4i3SZD16fRKJ1ZGb4qp9QL XlEsF8oKodWUi4PTu9/XdlUG9gA1pNqyjoA1KsmDLbgysBzBCd4nQcFsDELuCIbpAPhL 21AoZAsF7HFuXv/4+6Ros9QR2I6qyBtvICViA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IIyzRbatR38ttllEYMMotwwVkanyqchmaJcpYBpIki0=; b=QKYxmsiyqQ+2HHaZw77ysnM+Xi3p/obREgf1YqUxOyMzi92Yz3LpiqJDgwhs3CsGMk AQxE8IPevQnljWPC27m/jH0pYJmd0MajmeLZpaZORUu29gAz0RTj4+o+lI/5w2zTg6Lw yqpBN9m9iH2vUdfHNOrIwVt/t1fqEXpaJEL/UBooh6B3j0Sbr0zLNrnz4aYUwgWNl+N+ ddFPy9UUtaz3ctxHtOsXe/EjN5flMx8d7wWUGHpgbrAdQAkq1EoDVTyDnqcH4U1mlaKt DhtJBamm+kUPgfnqtOEqXsToCuW+OsW61KhePpuo+PX7f/g+/Bc9S09YUzQIUpAKm8Rj rmQg== X-Gm-Message-State: APjAAAX+/kkRMQHKjYZispwFbrWiBqdUNCG88yvpx6K5Rq9sKuJsPrHR Hw8VlLpbVuS2OkQuUCFG9rXFrvd2Yociw9X0lg8= X-Received: by 2002:a2e:3602:: with SMTP id d2mr13542107lja.112.1564141528767; Fri, 26 Jul 2019 04:45:28 -0700 (PDT) MIME-Version: 1.0 References: <3b922aa4-c6d4-e4a4-766d-f324ff77f7b5@linux.com> <40f8b7d8-fafa-ad99-34fb-9c63e34917e2@redhat.com> In-Reply-To: From: Joel Fernandes Date: Fri, 26 Jul 2019 07:45:17 -0400 Message-ID: Subject: Re: Limits for ION Memory Allocator To: John Stultz Cc: Laura Abbott , alex.popov@linux.com, Sumit Semwal , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Christian Brauner , Riley Andrews , driverdevel , "moderated list:DMA BUFFER SHARING FRAMEWORK" , linux-arm-kernel , dri-devel , LKML , Brian Starkey , Daniel Vetter , Mark Brown , Benjamin Gaignard , Linux-MM , Dmitry Vyukov , Andrey Konovalov , syzkaller , Hridya Valsaraju , Alistair Delva , Chenbo Feng , Erick Reyes Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 24, 2019 at 4:24 PM John Stultz wrote: > > On Wed, Jul 24, 2019 at 1:18 PM John Stultz wrote: > > > > On Wed, Jul 24, 2019 at 12:36 PM Laura Abbott wrote: > > > > > > On 7/17/19 12:31 PM, Alexander Popov wrote: > > > > Hello! > > > > > > > > The syzkaller [1] has a trouble with fuzzing the Linux kernel with ION Memory > > > > Allocator. > > > > > > > > Syzkaller uses several methods [2] to limit memory consumption of the userspace > > > > processes calling the syscalls for testing the kernel: > > > > - setrlimit(), > > > > - cgroups, > > > > - various sysctl. > > > > But these methods don't work for ION Memory Allocator, so any userspace process > > > > that has access to /dev/ion can bring the system to the out-of-memory state. > > > > > > > > An example of a program doing that: > > > > > > > > > > > > #include > > > > #include > > > > #include > > > > #include > > > > #include > > > > #include > > > > > > > > #define ION_IOC_MAGIC 'I' > > > > #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ > > > > struct ion_allocation_data) > > > > > > > > struct ion_allocation_data { > > > > __u64 len; > > > > __u32 heap_id_mask; > > > > __u32 flags; > > > > __u32 fd; > > > > __u32 unused; > > > > }; > > > > > > > > int main(void) > > > > { > > > > unsigned long i = 0; > > > > int fd = -1; > > > > struct ion_allocation_data data = { > > > > .len = 0x13f65d8c, > > > > .heap_id_mask = 1, > > > > .flags = 0, > > > > .fd = -1, > > > > .unused = 0 > > > > }; > > > > > > > > fd = open("/dev/ion", 0); > > > > if (fd == -1) { > > > > perror("[-] open /dev/ion"); > > > > return 1; > > > > } > > > > > > > > while (1) { > > > > printf("iter %lu\n", i); > > > > ioctl(fd, ION_IOC_ALLOC, &data); > > > > i++; > > > > } > > > > > > > > return 0; > > > > } > > > > > > > > > > > > I looked through the code of ion_alloc() and didn't find any limit checks. > > > > Is it currently possible to limit ION kernel allocations for some process? > > > > > > > > If not, is it a right idea to do that? > > > > Thanks! > > > > > > > > > > Yes, I do think that's the right approach. We're working on moving Ion > > > out of staging and this is something I mentioned to John Stultz. I don't > > > think we've thought too hard about how to do the actual limiting so > > > suggestions are welcome. > > > > In part the dmabuf heaps allow for separate heap devices, so we can > > have finer grained permissions to the specific heaps. But that > > doesn't provide any controls on how much memory one process could > > allocate using the device if it has permission. > > > > I suspect the same issue is present with any of the dmabuf exporters > > (gpu/display drivers, etc), so this is less of an ION/dmabuf heap > > issue and more of a dmabuf core accounting issue. > > > > Also, do unmapped memfd buffers have similar accounting issues? > The syzcaller bot didn't complain about this for memfd yet, so I suspect not ;-) With memfd since it uses shmem underneath, __vm_enough_memory() is called during shmem_acct_block() which should take per-process memory into account already and fail if there is not enough memory. Should ION be doing something similar to fail if there's not enough memory? thanks, - Joel