Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp69321ybi; Thu, 20 Jun 2019 18:02:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyno8NgbPOxDf16FwiSKFBKWvaCg6sbs6+UCHkmTuaASSuZ1HpYvZj2eWg2C1z4L0tAaju2 X-Received: by 2002:a17:902:2889:: with SMTP id f9mr78012888plb.230.1561078931170; Thu, 20 Jun 2019 18:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561078931; cv=none; d=google.com; s=arc-20160816; b=aazNUfZBNJJ6sqQ6jITrSKNavcZAZy5FyjF0kYT83zwlBJfrUUcNw9ndhz9QAxoU+D LaaBVnzpclmYnX2Hp2LNlW3JDKimCWHMiH4urDyHlm1rNZ8Wzyjp40jJ9wO5QDb4PnHa xmjEeK56XXfZluvKToMGKj5oHoasiAz9Y/z+rNpKgSC48bw9Ve7iis4nkQ3oQHXuB33A gydQjUSew0H6qbedf+VQ5kQxM1exUGPo0Ss122MlWOgnC076vCQltIjdRxz9hWePmntf tmf5Q2sJ9h3WMWz5xw01GXvuSNtJaExzaeAKdl5XVz99aOFeYS8qB7diAR5cCs/wJ1r1 oF5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jOk3PreZ3YiInlE3LTXkzPl68+QbundNai30bAJKnEU=; b=DRtpqFTYScylvAuDmskOTcjdcilSlcWKiVfPTFwi+wWXv2QQTOZuPQT/ackwwt3G0F RHci15zd9sGaIC5PV8+5SlJECiDiiqYdY87r9qyZdgZbdvA3DQMSD7slkgYmeqPU8Yqq 78i7UkBtvP8mAtKHrEqeaZTGgYWa6z6Ecq6JrEdg+sz5m183uNH1bJB99GKMe1qM41c6 najP5zBQsvcDowCNATA2vto7i23nwCTSNT1HmG2r9NJGXd3udYx3Yp5d0NLTxUdp26DN bfEaZ/2cCw2P7PfZbj9PXkjijafVBHxvH6Ih6bf2lZAnfFmzHZi8nIY+h3omyXFZ+ixf YAjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PbKjdPWc; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j62si1043766pfb.272.2019.06.20.18.01.54; Thu, 20 Jun 2019 18:02:11 -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=@chromium.org header.s=google header.b=PbKjdPWc; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725958AbfFUBBo (ORCPT + 99 others); Thu, 20 Jun 2019 21:01:44 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46940 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfFUBBn (ORCPT ); Thu, 20 Jun 2019 21:01:43 -0400 Received: by mail-pg1-f194.google.com with SMTP id v9so2453541pgr.13 for ; Thu, 20 Jun 2019 18:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jOk3PreZ3YiInlE3LTXkzPl68+QbundNai30bAJKnEU=; b=PbKjdPWcdAzMqG/JzK1HR0UcqG/UX8eh2967eEegjSLi4avW+I1MWzePzFoaR/RhDz v936+ryvXqtDcxrnJqsy5S/83EDuAVf5GwkEF/Kd7NU5M9kBznE739f8ulkLOKnCN5TP BgbRDjDHZ8uwDaNrUzaVY5sjhf5UK5VV4W7MA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jOk3PreZ3YiInlE3LTXkzPl68+QbundNai30bAJKnEU=; b=iGJ6hErWfJ0BFzM+UWt+b2ImcQoZ+uxz67xGpM22d4iy4HDqQyBlBtTWWXScm6RN1J W8zhl3U0uY6noVMid11G0rlISgvkhY5izwmDYR1MwK3/bJRPX9JmhkfNEdhthASO+1zr CBDwKpNFLf5/247bz8gEI54N5Dx3Mmf1tRt2y4WSQYv9VJ0kyR+F+AcZn6Wl4VjjA/NA 0FqCVDzip+766UCQcUa2jJjYYRHiZe4AKp3UYHQYvDJP6IMN21UUIharuuicM8uGxzOD dlId2ONyuYxIfaMR/oZIP1DGe/6RLSalZWDD9S+RGbHHj9uAVHdMJXBHvoEk9Zq3A9fl qMuA== X-Gm-Message-State: APjAAAULtw2l6evoh53hS8ClJJICbPxJVZLoNTPYNChw2zbfovH1I+e/ Jvy/BHt4Yi3/fdFsAcnuiOp5bA== X-Received: by 2002:a65:50c3:: with SMTP id s3mr15343980pgp.177.1561078902926; Thu, 20 Jun 2019 18:01:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v13sm650415pfe.105.2019.06.20.18.01.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jun 2019 18:01:42 -0700 (PDT) Date: Thu, 20 Jun 2019 18:01:41 -0700 From: Kees Cook To: Qian Cai Cc: akpm@linux-foundation.org, glider@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next v2] mm/page_alloc: fix a false memory corruption Message-ID: <201906201801.9CFC9225@keescook> References: <1561063566-16335-1-git-send-email-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1561063566-16335-1-git-send-email-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 20, 2019 at 04:46:06PM -0400, Qian Cai wrote: > The linux-next commit "mm: security: introduce init_on_alloc=1 and > init_on_free=1 boot options" [1] introduced a false positive when > init_on_free=1 and page_poison=on, due to the page_poison expects the > pattern 0xaa when allocating pages which were overwritten by > init_on_free=1 with 0. > > Fix it by switching the order between kernel_init_free_pages() and > kernel_poison_pages() in free_pages_prepare(). Cool; this seems like the right approach. Alexander, what do you think? Reviewed-by: Kees Cook -Kees > > [1] https://patchwork.kernel.org/patch/10999465/ > > Signed-off-by: Qian Cai > --- > > v2: After further debugging, the issue after switching order is likely a > separate issue as clear_page() should not cause issues with future > accesses. > > mm/page_alloc.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 54dacf35d200..32bbd30c5f85 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1172,9 +1172,10 @@ static __always_inline bool free_pages_prepare(struct page *page, > PAGE_SIZE << order); > } > arch_free_page(page, order); > - kernel_poison_pages(page, 1 << order, 0); > if (want_init_on_free()) > kernel_init_free_pages(page, 1 << order); > + > + kernel_poison_pages(page, 1 << order, 0); > if (debug_pagealloc_enabled()) > kernel_map_pages(page, 1 << order, 0); > > -- > 1.8.3.1 > -- Kees Cook