From patchwork Wed Jun 13 08:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 10461919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 35AF8603B4 for ; Wed, 13 Jun 2018 09:27:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24042288EB for ; Wed, 13 Jun 2018 09:27:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17A5628943; Wed, 13 Jun 2018 09:27:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 00127288EB for ; Wed, 13 Jun 2018 09:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:List-Owner; bh=LiGeS2mLXs8DywnGWCe/RZFKc9YaMgV2n8SnMHgihuw=; b=dT VSSsYWnmU7Km4XMFK3FrYAHmp/6xSom4r8bHtpdYQJpCObPIIFt4iJP6LnRQBvBGojRvRu1z+NeBD pGC13tSf6GSAUv8ExqM4pyQtJmtEqs945wxDEUpePKW0YDntnYgqefeVbYeXlC+zwAk3btI2mKnXn Dh22ZkPi/6TeSsuD3auxaFp3a9+Jxw/nBCUZyLVA/ExxnubLnSxH+OduU02c9O5oVXur3iAusrfCb FP9o1Ne+D5yni7/Zl4q/MJgP8oW9kn5GQjel/suaiwg2YiidL82kfRd9Vse18H74U1lHOBaI8cBZi H2ScAjBCsSfDTtIye5lPK6PpN6IU18nA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT23K-0002FO-IC; Wed, 13 Jun 2018 09:26:54 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT22v-0001Xl-N3 for linux-arm-kernel@bombadil.infradead.org; Wed, 13 Jun 2018 09:26:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:Content-Type:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HUnq++m5CppSQm+bcPQ3G6N6tBLG9IP2HZVNlu4Jyy4=; b=bWSst1Hmka1U6QphevYCPgkdnN I8044n4AL+byjjzPHZg70hzG/p9672EkhrqClBjgvnfTU0p6uUqJXW8mCjC8E0lDhWe6wYnNW3cOK J2/PXZjeExtbf0gqlmPr5TrRa1IYZ8bvpKAw0JgNscl6ZAY2hRXOg+0j51DA0PGVxSdAPt6Hrx93H 4rxSDR94MchqMjSkVK8XVB/2fcKSndj2xfygmsaqd4hZm0bJSqui0GpKvv59q/rKcs8bopxyE7XkR JcNyd/rU6+zWe8r3LkuJe63fBExzNJ/igDpbFFmOFq24vCgqeDHq+JefreOmZaYmX6tOF/EUDULYg QJ7ymM0w==; Received: from mailout1.w1.samsung.com ([210.118.77.11]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT1cd-00031W-RV for linux-arm-kernel@lists.infradead.org; Wed, 13 Jun 2018 08:59:22 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180613085853euoutp01864cf5564e47f00529e4e4831047f26e~3rJA7Q1np1231912319euoutp01b for ; Wed, 13 Jun 2018 08:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180613085853euoutp01864cf5564e47f00529e4e4831047f26e~3rJA7Q1np1231912319euoutp01b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528880334; bh=HUnq++m5CppSQm+bcPQ3G6N6tBLG9IP2HZVNlu4Jyy4=; h=From:To:Cc:Subject:Date:References:From; b=iLDYlftPiTDRaR5JGAS8QUBzjgAV6e+d4DbKJ4lp7xEnHs41oxszdUzd5mc0K/jR1 2+Uh0uJSqHkw9h9TpLvFQHyNjZ/9DYh+KIM9Qv8w+YBYnIu3T3GNv4mZj/HDYnpoQO zhtobZuSafqWovHFddl1EgQ1kBKkppbDRtkeiGBI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180613085853eucas1p16799205776268eeb412e02aa82262e2f~3rJAMuGQi3167631676eucas1p1O; Wed, 13 Jun 2018 08:58:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 3F.39.10409.CCCD02B5; Wed, 13 Jun 2018 09:58:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20180613085851eucas1p20337d050face8ff8ea87674e16a9ccd2~3rI_9nj8b0455904559eucas1p2C; Wed, 13 Jun 2018 08:58:51 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20180613085851eusmtrp1c914d3cc1cb11c98864055332de6e22d~3rI_sd8iv0606306063eusmtrp15; Wed, 13 Jun 2018 08:58:51 +0000 (GMT) X-AuditID: cbfec7f5-b45ff700000028a9-c3-5b20dccc0771 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E8.E8.04183.BCCD02B5; Wed, 13 Jun 2018 09:58:51 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.116.147.25]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180613085851eusmtip2e855b02eef7a56d620ae35bb6b4515a6~3rI_SvkQB3117331173eusmtip2B; Wed, 13 Jun 2018 08:58:51 +0000 (GMT) From: Marek Szyprowski To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] mm: cma: honor __GFP_ZERO flag in cma_alloc() Date: Wed, 13 Jun 2018 10:58:37 +0200 X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42LZduzned0zdxSiDZ6cNbWYs34Nm8XK7mY2 i02Pr7FaXN41h83i3pr/rBZrj9xlt1hwvIXVYnZjH6MDh8emT5PYPbreXmHyODHjN4vH5iX1 Huv+vGLy6NuyitHjzIIj7B6fN8kFcERx2aSk5mSWpRbp2yVwZazb381ecI+r4uENvQbGcxxd jJwcEgImEhPvr2DvYuTiEBJYwShxdOIkNgjnC6PEpJcNTBDOZ0aJbzf+scO0TD/9kxEisZxR 4sW561DOV0aJ7V9vsoBUsQkYSnS97WIDsUUEYiS2HLnPDFL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S7NS9dLzs/dxAgM1G3Hfm7Zwdj1LvgQowAHoxIP74OL8tFCrIllxZW5 hxglOJiVRHgnTFWIFuJNSaysSi3Kjy8qzUktPsRoCrR8IrOUaHI+MIrySuINTQ3NLSwNzY3N jc0slMR5zxtURgkJpCeWpGanphakFsH0MXFwSjUwzlztE7ri2vcClj+nZkjtNGg57ZKUVJYv Kh97RPjzeWnxFU3FJaz/r4Sxf7M/J/+vfi6f8k/j6QsbtBfa7RK+m7Kk1vZkf+d6T1mlAyc4 ay901MVrf/m9KOZn+zPJsrRin5+xgpx50qe7eURvlTnsfXh7s+i72G/vFec/Lpes5I6xXC/y LqBKiaU4I9FQi7moOBEAFSZDqGoCAAA= Message-Id: <20180613085851eucas1p20337d050face8ff8ea87674e16a9ccd2~3rI_9nj8b0455904559eucas1p2C@eucas1p2.samsung.com> X-CMS-MailID: 20180613085851eucas1p20337d050face8ff8ea87674e16a9ccd2 X-Msg-Generator: CA X-RootMTR: 20180613085851eucas1p20337d050face8ff8ea87674e16a9ccd2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180613085851eucas1p20337d050face8ff8ea87674e16a9ccd2 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_095919_888186_12D0C4BD X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vlastimil Babka , Andrew Morton , Joonsoo Kim , Michal Nazarewicz , Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP cma_alloc() function has gfp mask parameter, so users expect that it honors typical memory allocation related flags. The most imporant from the security point of view is handling of __GFP_ZERO flag, because memory allocated by this function usually can be directly remapped to userspace by device drivers as a part of multimedia processing and ignoring this flag might lead to leaking some kernel structures to userspace. Some callers of this function (for example arm64 dma-iommu glue code) already assumed that the allocated buffers are cleared when this flag is set. To avoid such issues, add simple code for clearing newly allocated buffer when __GFP_ZERO flag is set. Callers will be then updated to skip implicit clearing or adjust passed gfp flags. Signed-off-by: Marek Szyprowski --- mm/cma.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index 5809bbe360d7..1106d5aef2cc 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -464,6 +464,13 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, start = bitmap_no + mask + 1; } + if (ret == 0 && gfp_mask & __GFP_ZERO) { + int i; + + for (i = 0; i < count; i++) + clear_highpage(page + i); + } + trace_cma_alloc(pfn, page, count, align); if (ret && !(gfp_mask & __GFP_NOWARN)) {