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: 138428 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp445036lji; Wed, 13 Jun 2018 01:59:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGNrcJgmT914oiyaebC0ZYvf3uO4b1+3Zf4sGz94tdovqZUTJPVEBUoubwdE5A+ingOJfk X-Received: by 2002:a65:504a:: with SMTP id k10-v6mr3326052pgo.151.1528880342290; Wed, 13 Jun 2018 01:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528880342; cv=none; d=google.com; s=arc-20160816; b=XoQZ2zYf1wAkczO6ccPbDY5EBYXhHXFTInTR0MKJDm+K4Ar0lcRouwgxTdTEB4Ut75 st7EgnRHpxGP0tluirpt44EjyozBAwANcaYxwSPFfYB0YGuVO9UTZcFIbrD8YWTiOVOo ueew9kLVSJw+ujcFepUE0Nr/pNE5/oUI7W5MrrVWxYGqK87S4kqAxWfqkMEz7sQop1P3 y+3eILj++yyB66MJeUD6ZE7Yi0sDwGxf2SFII2qR4HMjamXPIu8Z5+g3MuJAZo0eNlAq eVVw5jDhbmZJ/dj7pO37iK0N/ZUbPLW4Dtt8yK4XeOdPZTryOoDhFqgc321B05zkxgr7 eiHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=HUnq++m5CppSQm+bcPQ3G6N6tBLG9IP2HZVNlu4Jyy4=; b=PJj9TvwMRIeul9JYO2Ce0nT98CcTsytw8ac8eaG5dys8vxVDItl9/hMVxpHaP7ZdNh /CNAMo+Wii+faLe5cKAEvzX+SAExlMlI/tQbkaXeOVvIQbJqFyI7YjexBS2PzyX3VPjo usYBpUmE6p3GRzWzHHaKGAsiTveWSvNt1RdvVZ0CLKP/k6iepigOiIi47SL7OwzHgnj4 M6yNZZ4nGO9BPgJxSaYX92bOVuQefabVJ6qLtWoMccz5oAKkqxuD13oXv2Qy0u14xzUW o8L9UIzfvK7vmySOYpXliXMm94+lMXMRRsRpvkm/Q69Hd5vpT4cbnyTH+ySq9dt+OIl/ gF7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iLDYlftP; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10-v6si1862321pgc.261.2018.06.13.01.59.01; Wed, 13 Jun 2018 01:59:02 -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; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iLDYlftP; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934730AbeFMI67 (ORCPT + 30 others); Wed, 13 Jun 2018 04:58:59 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:55341 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934436AbeFMI64 (ORCPT ); Wed, 13 Jun 2018 04:58:56 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180613085854euoutp018ff3cabedf37a09c69947a5e27c3377e~3rJBjGyat1235812358euoutp01V for ; Wed, 13 Jun 2018 08:58:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180613085854euoutp018ff3cabedf37a09c69947a5e27c3377e~3rJBjGyat1235812358euoutp01V 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 i02Pr7FaXN41h83i3pr/rBZrj9xlt1hwvIXVYnZjH6MDh8emT5PYPbreXmHyODHjN4vH5iX1 Huv+vGLy6NuyitHjzIIj7B6fN8kFcERx2aSk5mSWpRbp2yVwZazb381ecI+r4uENvQbGcxxd jJwcEgImEhPvr2DvYuTiEBJYwShxdOIkNgjnC6PEpJcNTBDOZ0aJbzf+scO0TD/9kxEisZxR 4sW561DOV0aJ7V9vsoBUsQkYSnS97WIDsUUEYiS2HLnPDFLELHCWUWLmoSuMIAlhATuJKSdb WUFsFgFVid9v77BCrJCXWL3hAFiDhMB7Nonp56+BTeIVKJOYtus8M0SRi0TPow4WCFtY4tXx LVD3yUicntzDAtHczCjRPmMWO4TTwyixdc4ONogqa4nDxy8CreMAuklTYv0ufYiwo0TLqZts IGEJAT6JG28FQcLMQOakbdOZIcK8Eh1tQhDVahKzjq+DW3vwwiWo0zwkGjbsAJsiJBArsW2f 3gRGuVkIqxYwMq5iFE8tLc5NTy02zkst1ytOzC0uzUv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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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 2.17.1 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)) {