Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3635511imu; Mon, 28 Jan 2019 08:11:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN6qr1TJzvE3aC85VzLfzR0E5UjiArpimEpHHQe2HrBf8xqIkZRGQVsnNcGbv2Gk1RPUC+NC X-Received: by 2002:a62:1542:: with SMTP id 63mr22582452pfv.230.1548691915482; Mon, 28 Jan 2019 08:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691915; cv=none; d=google.com; s=arc-20160816; b=wvxcilE2FKYBVNn9ynl/dAa1sRMCRrCishyV7qM7xgaKazLY8IoE8yCpxI9sWrL5kb lSTnNFG08TPG7maxy7Tny7ibHCAw81qYF/BMLJnROJUNtTTOlO8msiti0ubqMvV4c+gf q1akpzn8eRutK+934gwaDQdDx5mnOA6xwgXR6OXqHKwmYEycV9ZBtYvJoRGuv7+i5r82 Diggarg9gPe28AA1LsEXXK2Dpqz/Me2BMWwNH55Uz8x7w4slAjPuc8PrQRzdo//EjJE+ ISKO9vCNNdRhDgJYJNNVzPUpt+YWIXB1Nim7jDAlHChCDYjHv9AT47Bxj0QZhDdQSxYy 9xrA== 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:date:subject:cc:to:from :dkim-signature; bh=9tWbXjPx+ylNQqVYDh1Ju/QGShmOIh48UEWicfqbXlc=; b=e+DQdWvYkY2d0aavIdJGY3cO7+WmrOWf8Htua3OYyboWoxnoEO5MyI+LoE71vefqEg sBNouTSRtz2Q2+dkiC1QeVPXp3DgMn9m5H0YFlhgLNvKa32aGtkW9hXr1d2577T4moj1 ptwQGJoDGZXgKchzU2gvEz/gkH3g8ATfoRsaQsE3mv70Aggzz2qmTXLNMWVmRLKenK4B 9pSVovcajmQvb7rkZBS+bL0GC7uIFGyQc3v/q+wi4Wlts17nTJmaIfPBmSNSfCDKNwNi RjT/QjX7Iz5TjecHRszCmF8J2J9vxOj3sbBVn0fjfrBhslRMn820hzwIXTQRj9A9eiEg hVWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FC+tjslz; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si18894302pgl.539.2019.01.28.08.11.40; Mon, 28 Jan 2019 08:11:55 -0800 (PST) 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=@kernel.org header.s=default header.b=FC+tjslz; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732862AbfA1QKp (ORCPT + 99 others); Mon, 28 Jan 2019 11:10:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:37022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731666AbfA1QKo (ORCPT ); Mon, 28 Jan 2019 11:10:44 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DF8A2084A; Mon, 28 Jan 2019 16:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691843; bh=iMPET4x1Ri3FMmeFZ87YAw+rJQU9OwKtkcfiyE1nWo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FC+tjslzyI5EGb9RLk2BMcsJ16icWWiZPVjxrPaypOhQUTQEQD8FCx7QeLTnqmhi4 T4RD5T+kKtrclpPuoFGhSOmlRYGHh90nG1A+dQVvknFB4RO7Uyi2G1nTdhQnuu/lS4 nKHAcgeU4lMQH1K0WqMqpWDiWI1FIh/BYXKUD80Y= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miles Chen , Joe Perches , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 235/258] mm/page_owner: clamp read count to PAGE_SIZE Date: Mon, 28 Jan 2019 10:59:01 -0500 Message-Id: <20190128155924.51521-235-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miles Chen [ Upstream commit c8f61cfc871fadfb73ad3eacd64fda457279e911 ] The (root-only) 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. [akpm@linux-foundation.org: use min_t()] Link: http://lkml.kernel.org/r/1541091607-27402-1-git-send-email-miles.chen@mediatek.com Signed-off-by: Miles Chen Acked-by: Michal Hocko Cc: Joe Perches Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_owner.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index d80adfe702d3..9ad588444671 100644 --- 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 = min_t(size_t, count, PAGE_SIZE); kbuf = kmalloc(count, GFP_KERNEL); if (!kbuf) return -ENOMEM; -- 2.19.1