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: 10461905 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 01CB9603B4 for ; Wed, 13 Jun 2018 08:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0769F289E0 for ; Wed, 13 Jun 2018 08:59:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFDAC289E9; Wed, 13 Jun 2018 08:59:02 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 861F5289E0 for ; Wed, 13 Jun 2018 08:59:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5174B6B0005; Wed, 13 Jun 2018 04:59:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4C74C6B0006; Wed, 13 Jun 2018 04:59:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B68F6B0007; Wed, 13 Jun 2018 04:59:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id E6EBE6B0005 for ; Wed, 13 Jun 2018 04:59:00 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id z11-v6so1022111pfn.1 for ; Wed, 13 Jun 2018 01:59:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-filter:dkim-signature:from:to:cc:subject :date:message-id:cms-type:references; bh=HUnq++m5CppSQm+bcPQ3G6N6tBLG9IP2HZVNlu4Jyy4=; b=KMrF5S0EAwthzGLGZeMYwecWbSKw8uar4vPQs684ZKFTTtOvs1MVQ6GAEAcb5RefOL DnpmSqa64ClV42D8VTSFaVM+PqvBxS7sbBKXHCURaYJaIp+Ks6PPyLg+yKgZi0VDHbXe dmwoCAjN3e2QZZC3M8Rtb0PgGOvfgiFLinAh8B9eBAxmSQgb3VtFVELYwSiGOzZnETQA b4ZYxKXeuPxbj47clFDZf0FHYCqD1aiTGqVgcxUZ1Mbt9O5sbvxEPIWCHj4jEW20Om89 BUImSf2+WRGanZHPuCxUWGV4MIxtXjniow4pnwiH0YdKnxBwx2CBV4WqfATHRIQ0i1p0 Jd5w== X-Gm-Message-State: APt69E0SSlX+B328dGRWMxMOOkiyjuV0u7fxkOUWfiNhR/f2sjSYdH9a z5eYoMmLxN81Ew4lIZXasHs6JQDvINWSlIl4zdj+MI26nh+CYZSzG+O8gwXuzRfiFJq5ZUkVtOD Z0A0iD9B0ZX1SFBtV3HTQCYLy2CGVHRpUK5L1Vhf7mdxX1yA7Sv2g5z2d+UE+dvWZdQ== X-Received: by 2002:a17:902:8ecb:: with SMTP id x11-v6mr4340061plo.308.1528880340587; Wed, 13 Jun 2018 01:59:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIf+aFEKLnfIj6zjmyUal2x7O8rjfnsY0suDAwTe7yH+L4I8NOJj0kDdJL3LCX4XU+J+BvN X-Received: by 2002:a17:902:8ecb:: with SMTP id x11-v6mr4340015plo.308.1528880339924; Wed, 13 Jun 2018 01:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528880339; cv=none; d=google.com; s=arc-20160816; b=SKcxMv/Ru60e0PuFcy+VsgzCo9ZZmmdRv6t/BDLsRQckzeWzPlHTBrEq7DYrSDWH4I oaVoFaT63CMz9Vxj1z15IZUfUfx0dRTXXVb5woBasOS+BnAIITjydvJVwaEw5jIQFQKH ZeKINQBWckdSm1FLDtUV+gcSJZmIEyl62N1f90GHr3u1XKb1I7xqUwsDrE7piueJ6kI7 Y6p9emKQPVPhhrB/dEBhM4S7jnFHApMj03BJotO7SAkN62jmm+w6Wzrx3OLzvjJOIbHd s1VWZn3jDbIVUS/XB5ccDO/5K6X/dtsbspVuivmD382oxc5+wTiHdVZaVH60b8F7t1v4 uVAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=HUnq++m5CppSQm+bcPQ3G6N6tBLG9IP2HZVNlu4Jyy4=; b=UaQhHO5FQ1EZL8oTDbm2/3aKrUabLEfsB/6w2f7eEFvzHNTASz/EEiCGSQqxqUL0aA M6QLCrRZ6rqNFHXaCTSSBTd/5H14W+J3BpnUx4V8EYyNQh0flv06NTIlzX/XezZ3N5mx rXPLxvJAck7iYz0hM3Txt+B6+3+32jmJm+3y2kvNQWxAiS1SjgNf+XL0sDJsrVlQ9OXX rnjhO36hj8A1C/RZbyDsOHXRpVVD3ws+tWvbPpFLotiUIMfzXcf+dKrZR7A4CwiXChKp 9IvZEQt12Un1gf+CRuveim0kGJ60uPNa+2q3jHI9BiyODE7WWboBm/TGhBBpWSyHIoDp ipFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iLDYlftP; spf=pass (google.com: domain of m.szyprowski@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=m.szyprowski@samsung.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com. [210.118.77.11]) by mx.google.com with ESMTPS id k124-v6si1937769pgc.519.2018.06.13.01.58.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 01:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of m.szyprowski@samsung.com designates 210.118.77.11 as permitted sender) client-ip=210.118.77.11; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iLDYlftP; spf=pass (google.com: domain of m.szyprowski@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=m.szyprowski@samsung.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180613085853euoutp01abbb85cde665a487e04cb30a6f67a263~3rJA7Uz8m1185911859euoutp01D for ; Wed, 13 Jun 2018 08:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180613085853euoutp01abbb85cde665a487e04cb30a6f67a263~3rJA7Uz8m1185911859euoutp01D 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 Cc: Marek Szyprowski , Andrew Morton , Michal Nazarewicz , Joonsoo Kim , Vlastimil Babka 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 i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JVcjILy6xVYo2tDDSM7S00DMysdQzNDaP tTIyVdK3s0lJzcksSy3St0vQy1i3v5u94B5XxcMbeg2M5zi6GDk5JARMJKaf/snYxcjFISSw lFFi3cJTzBAJGYmT0xpYIWxhiT/XuthAbCGBz4wS7/6WgdhsAoYSXW8h4iICcRIXXh9lAxnE LHCRUaJn31awhLCAncSUk61gg1gEVCV+v70DZvMK2Ehcm93LCLFAXmL1hgPMExh5FjAyrGIU SS0tzk3PLTbSK07MLS7NS9dLzs/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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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)) {