Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp613906ima; Fri, 26 Oct 2018 03:57:54 -0700 (PDT) X-Google-Smtp-Source: AJdET5egXv0LnpBRCIwqs5RA6vEu4+JjTu1Yx2+GmNhaa6mNOEldTi4Cs3EERpKLX0Yne3c4kHZN X-Received: by 2002:a62:460c:: with SMTP id t12-v6mr3255652pfa.206.1540551474920; Fri, 26 Oct 2018 03:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540551474; cv=none; d=google.com; s=arc-20160816; b=YLW5SPg6Wk+0ltdub44g5FoiffhKfgNKWQTP7/DTX3tYO9O23DEwnuio1QQ2Vh06x5 EDGNpvmKQrQmtSDFdNXhk5WlDAHy7UlvmHtj/D6TZ9gL6CVtJmlFCdyezXDBwSZgKfFh P2MLKhCVO7icmHltyKWvWUHFufA7x+ekOlrXmIyZhwRl7mC+GKPMRkAmmYIheDJ+Iw84 0YQ/2GiVjHUA9PKT56xF7lp97RtY2iICCN0H/3LdfpaeUfy6BltAy4cC5/74wz6EklqG fs4Q0w4MKo7x7Z1nYknIoqHuVRW55psKuy/XdelPPEtnvFjYRX+aRjpuovDL4ya/dlvT bXUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1DhUBU2/AIkhwcMKzcd8CjYWH2LSLMNqoP14d/RfOvQ=; b=Bo+P20acm40JdrcusF02xogqSestkgwYOqBl26KOP4PDXM2Hcv/TABJhamYDE0uTUI MF7UpJWHtx1XNKYAn7L+TVKdIZnvkWQHyDnKZNYUm/jI3tY1ngTD7RrCW8gdQrOAobz9 aKuqqHIqBmQ3kqABoq7Tv58DejTxTXYtOpKjLfjEnptb6+IJV9aHT0AcxRgjOBaZOHC+ 9QTS8kKOnj++DS7wsi4fRd1j03zN+xNq4jEN/7Aub+f+rH/li21BNUDB8jXBtXDPyVGj NZkupeb8eJ+glsz8Y+jh1aamToA7C80/oA7s8ivuQvIWbN65zkrTiK83Qz2XBN25iA5F LX+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si10645863plr.267.2018.10.26.03.57.39; Fri, 26 Oct 2018 03:57:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727491AbeJZTdg (ORCPT + 99 others); Fri, 26 Oct 2018 15:33:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:47588 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726275AbeJZTdg (ORCPT ); Fri, 26 Oct 2018 15:33:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 76A82AE86; Fri, 26 Oct 2018 10:56:58 +0000 (UTC) Date: Fri, 26 Oct 2018 12:56:56 +0200 From: Michal Hocko To: Matthew Wilcox Cc: miles.chen@mediatek.com, Matthias Brugger , linux-kernel@vger.kernel.org, linux-mm@kvack.org, wsd_upstream@mediatek.com, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] mm/page_owner: use vmalloc instead of kmalloc Message-ID: <20181026085410.GA8277@dhcp22.suse.cz> References: <1540492481-4144-1-git-send-email-miles.chen@mediatek.com> <20181025192701.GK25444@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181025192701.GK25444@bombadil.infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 25-10-18 12:27:01, Matthew Wilcox wrote: > On Fri, Oct 26, 2018 at 02:34:41AM +0800, miles.chen@mediatek.com wrote: > > The kbuf used by page owner is allocated by kmalloc(), > > which means it can use only normal memory and there might > > be a "out of memory" issue when we're out of normal memory. > > > > Use vmalloc() so we can also allocate kbuf from highmem > > on 32bit kernel. > > ... hang on, there's a bigger problem here. > > static const struct file_operations proc_page_owner_operations = { > .read = read_page_owner, > }; > > read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) > { > ... > return print_page_owner(buf, count, pfn, page, > page_owner, handle); > } > > static ssize_t > print_page_owner(char __user *buf, size_t count, unsigned long pfn, > struct page *page, struct page_owner *page_owner, > depot_stack_handle_t handle) > { > ... > kbuf = kmalloc(count, GFP_KERNEL); > > So I can force the kernel to make an arbitrary size allocation, triggering > OOMs and forcing swapping if I can get a file handle to this file. > The only saving grace is that (a) this is a debugfs file and (b) it's > root-only (mode 0400). Nevertheless, I feel some clamping is called > for here. Do we really need to output more than 4kB worth of text here? Completely agreed. Let's just clamp it to a single page. Userspace can easily loop around the syscall. -- Michal Hocko SUSE Labs