Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1380230imd; Thu, 1 Nov 2018 14:49:44 -0700 (PDT) X-Google-Smtp-Source: AJdET5eHngbnH8q7zJMBKKahx67cAuC6kwnqOTb8Gqhz6ubJlCpfBXieM8lhTGd25c2cRqysyFmq X-Received: by 2002:a63:3204:: with SMTP id y4mr8631711pgy.41.1541108984456; Thu, 01 Nov 2018 14:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541108984; cv=none; d=google.com; s=arc-20160816; b=eIbG01zj0ywGB43xyJCcW6/tzfqe+/jR0Z0YXllIeuUxkTa4ki8tvkUWxS2EATI+n1 k6YPy2d74V0+rsejWu4/rF721oTwYjTMefPB3iZC9rzjvkoSGT0x5HPtx6xzl6Weq72r Ho60FviYT0YIPWuHMcWJWxoSmjfCvAv2fcFxD+5zJ3e2ma9TsS+vdx0Z9PTzI6g9apTD xjjf26hxLOqJKZpEVtqDx3p/bFpE3aFN+/zi2n/paO4zt4Lf1rB99NU5sST0D6K6/lBD jH/xlIOI3mrZFLnxHszroiRvoJpDIE7sEpETgZ6gwqO/HvL7yYlBjvbhvrKjozX70Dcn g70g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=VkWh30E0KhZj4e7fiw/S647wlByne+ZkdhYGdZ4YGgo=; b=eoQsJz7CHXUi2WQzk+J3paN8GWZ3NtM0OOiVUfbdcWzoAbBEsP7zUFcseXad4AlxS1 yWVWPgZmYi1twgikdiyroglwZrM82jAa68vSbH9IHgPmvDYxo42Shsd56KcqRlESCUA+ 6NN4fqD5kHrDBAcy/qKm7zbYIfFafGjQSNQ1iBzegaq14QR5Wn+waa8CeG3fO6A61V5W lf4HGNsjjomSbtzePo9mLlkrBaaWIhLo9ywxK9rpwRyF8S6/+Qw32dkTDfwgcLGAcv7U Pi6cSODcvXEyEM+6pr7HAB4gIhRw6tUIaud3DqfOBhIHgPIhe0753QR/DrRkRT+ce3MG Q2LA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2-v6si25878283pfa.160.2018.11.01.14.49.29; Thu, 01 Nov 2018 14:49:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727518AbeKBGwQ (ORCPT + 99 others); Fri, 2 Nov 2018 02:52:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33824 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbeKBGwQ (ORCPT ); Fri, 2 Nov 2018 02:52:16 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 815D4AA6; Thu, 1 Nov 2018 21:47:29 +0000 (UTC) Date: Thu, 1 Nov 2018 14:47:23 -0700 From: Andrew Morton To: Cc: Michal Hocko , Joe Perches , Matthew Wilcox , , , , , , Michal Hocko Subject: Re: [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE Message-Id: <20181101144723.3ddc1fa1ab7f81184bc2fdb8@linux-foundation.org> In-Reply-To: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> References: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2 Nov 2018 01:00:07 +0800 wrote: > From: Miles Chen > > The page owner read might allocate a large size of memory with > a large read count. Allocation fails can easily occur when doing > high order allocations. > > Clamp buffer size to PAGE_SIZE to avoid arbitrary size allocation > and avoid allocation fails due to high order allocation. > > ... > > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -351,6 +351,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, > .skip = 0 > }; > > + count = count > PAGE_SIZE ? PAGE_SIZE : count; > kbuf = kmalloc(count, GFP_KERNEL); > if (!kbuf) > return -ENOMEM; A bit tidier: --- a/mm/page_owner.c~mm-page_owner-clamp-read-count-to-page_size-fix +++ a/mm/page_owner.c @@ -351,7 +351,7 @@ print_page_owner(char __user *buf, size_ .skip = 0 }; - count = count > PAGE_SIZE ? PAGE_SIZE : count; + count = min_t(size_t, count, PAGE_SIZE); kbuf = kmalloc(count, GFP_KERNEL); if (!kbuf) return -ENOMEM;