Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9979330ybi; Wed, 24 Jul 2019 13:26:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMPpN8K034YKpuo67klJEnWFnMQ3Cb9zQ8cRhObJqvhtinAjakhgprtvW9DwT6z82f4ln4 X-Received: by 2002:a62:3283:: with SMTP id y125mr13307751pfy.83.1564000000657; Wed, 24 Jul 2019 13:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000000; cv=none; d=google.com; s=arc-20160816; b=nWN0BbMYW5DKgZj6wQBDvNUVpVWNMKKU4lpMtLMO3Ba9Z3r7hr557izyxF10ACzQS7 W4frGixmVqizcJ4ZSGHV6gfr4W6b3w17Dw1PviJkexW7KJPwMPTNelccF+yPmhDteRpM fpvpHWLsmAADuKkhJjp/a3hXPtkIQSyJIZM8iOYZW3yp/z9rseprF325j4UpTMMtkFUH LRPDzvYHcHoh5iVyL3HdvKofEI4aAFMTwIxabLjMsIeXhnlA33XOd3DHn8NlNhUkdQEb oxDIOqIGlqp99zLybfKuzajD7DZXCluHlnkDHE858jvu8zp+aBeo2fzioF+L/7Wf3CkG OsGA== 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=QhT2aDY6DDwFo4u6pSSbFcjckneqY/fJmJSPh2en2QU=; b=SQMeOyOeHR02i1ZJtcGQMZzq9H9WU3tzPpLvLdOMP364Kgr4GB+pV2DI+DNwpfqDGn G8PzZDPbaPTD92z/+IQtI13TvplhFoTliDSAeUf3B3Qirbm7+zKe2QicKlQh/oCvEKWA p/FN+ZP0WuEhZfQ8LEIK5u9fmqZkEY6EPOV2Rf+OpgA8ZSzScedeGQJBu4ww9StpSi+K ZsVtbXnE/VvL1AJoyV4IZfp0ZPHqQ3ITpIqy+phDuHGLB31x8HtgsjHZGwbKFeceDKKd qYEEJP9nWK4yVWqADnJkMXOTNMKMYppVwdRouJ7xLsd+6QLEixnZHaJdmoVylvfxfJxn DM3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=exDKJ9fg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j36si14111335plb.77.2019.07.24.13.26.26; Wed, 24 Jul 2019 13:26:40 -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=@linaro.org header.s=google header.b=exDKJ9fg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390906AbfGXUYG (ORCPT + 99 others); Wed, 24 Jul 2019 16:24:06 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39150 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389760AbfGXUYE (ORCPT ); Wed, 24 Jul 2019 16:24:04 -0400 Received: by mail-wm1-f68.google.com with SMTP id u25so32370438wmc.4 for ; Wed, 24 Jul 2019 13:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QhT2aDY6DDwFo4u6pSSbFcjckneqY/fJmJSPh2en2QU=; b=exDKJ9fgAtICWDsB/RyvdCl1jI5YfgCIMwTNcxzkx1dyGll/JyL2AkvfnRrYbEirOB SEerS90nbZ0Y7uMtaafsNIrKrn2E8fDeOQgPH6N7PGG/abR8nOS6fvcaIr90v+MoUQKL Ya6XED0C/nS/Tu4DavDXSBDkL98MKY8aQ7cX7xm2OvAUaFe02AX21Q5ZVMnonR86zf17 jiYfPhij00tvovhGp4mpN1FJt4aO8yIzLriVTZilkdXv0YgY3MVNNVFA64d7rNVzPt7/ uDoAdw/I9wt7F4M+AoQ+DsbgfrLlirjsYmK30WF8s1pOpJ9mOGqbMiO76979hv3CBGmj 6/GQ== 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=QhT2aDY6DDwFo4u6pSSbFcjckneqY/fJmJSPh2en2QU=; b=iesNvni7DuHBSeYLqR9Y8/gvDzlq/9zBOcVbULmfLoocF+I3BHONXN8dQiUM4NZ9TP 9SkaAwO7hHSQU5RzdQRy/Eoph4B86IdIUbE5L58yD4LDp8ByX70/RSfMNPd68sAMvMN/ N2EdMDNedEOtglKq4+XuhFjdaloJousfMTcOSsTgvefDEkRxEGvvYdh0YQpjb6s4TWhg S25gENY3QUfWfdxBw6UE4FoXh7Mvv7BpQFkEgVlbT9nHUQ604UMn5GUbi4U2Iik6D9Hi 6+jmjyEel1rADGaHIuSdxBPQVv1iuKRZQ67Jo7KWDOHCuymUWdgp1trMhdYTi3wTDae6 xH1Q== X-Gm-Message-State: APjAAAX3a0ZZfU7MueKoMGEa084DiF1Pcq3f2lv3zuADK3OwQk0lCDqd hlZQfC8s7tSGQl2Lvu5nj5641waWAUEJNR5KCdIwRQ== X-Received: by 2002:a1c:dc07:: with SMTP id t7mr78697953wmg.164.1563999842462; Wed, 24 Jul 2019 13:24:02 -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: John Stultz Date: Wed, 24 Jul 2019 13:23:50 -0700 Message-ID: Subject: Re: Limits for ION Memory Allocator To: Laura Abbott Cc: alex.popov@linux.com, Sumit Semwal , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , 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 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 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? thanks -john