From patchwork Sat Apr 3 05:13:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12181807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A50ADC433B4 for ; Sat, 3 Apr 2021 05:13:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27059610CB for ; Sat, 3 Apr 2021 05:13:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27059610CB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3645F6B0074; Sat, 3 Apr 2021 01:13:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 314726B0075; Sat, 3 Apr 2021 01:13:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DCB46B0078; Sat, 3 Apr 2021 01:13:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id F3DD36B0074 for ; Sat, 3 Apr 2021 01:13:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 97B9D1AEC4 for ; Sat, 3 Apr 2021 05:13:37 +0000 (UTC) X-FDA: 77989888074.26.EB2B3F2 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf07.hostedemail.com (Postfix) with ESMTP id 0F19FA00038E for ; Sat, 3 Apr 2021 05:13:36 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id v18so5994264qtx.0 for ; Fri, 02 Apr 2021 22:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=5e19wUdjdODQtGD2+GvA+Yzt0Qe0WeByd74Ygcf0qpo=; b=RSLGuy7Kh37CaGR59OvN4TwyzsJg7oifTMmm9Nxlu2Ybw6NQiYdi+9tHOptypt1958 j2fehMNyvamzGtEfEKt+mFLdy/eQ9ekiTaTVZ9XbAaXNpjUYBslWwogJlOz1Ie+sJ6J6 LG7JiHDC1Ko7EKqax9gNaStHYCMS2hMagAVPX5bli60EN4ycotVrfugd2bbo7AIRddR1 11ntZ+a+0I4nGoHiIzAV3dA9vFD9lypn6ncRdNP/d3SxBmDBPer9Nwa/MhqmuJHWo4uH VrX7GxFpP4xjPIhy38IwB1h4B2Xj6ZVl9FIWFwIYFpe4MYLQKEeZ/NUL12bEfZ2/S9oh bu5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=5e19wUdjdODQtGD2+GvA+Yzt0Qe0WeByd74Ygcf0qpo=; b=ds8ka9P0qSQ+C6YtIEQ5T8Gog+9k/7Dx26HTCWRjFaCTrbs/yeii5l657nR2Ij1+ep oTkI3gycZrOpiC36qLDq7F70z93lskflehxOxSlw1Wrxfe7U6Acfmk+gpGbzEsH0piAb 5y38zqduprN8WsNFFuthN6n27kofQhDdxhhuuaSKKxcoheZDFTPwzrKTvyT9NHyTLeN5 i8Wi2Snwjt0SrOl+hYzb+U7PG8cD160sd1NaXcGuFzMZ23BDdoG8aDHtWcRs9ssAcUl8 VvQ4oc3UD1RVvVkhd0Wz2VlccLdizXN4jcUIglvDZ27MI/hD9mSg22U9GeP1VdouhOeh 915w== X-Gm-Message-State: AOAM533KU9p/haiazo+pwoLfQ/Abzqdvc/Sfc3Xd8fCK93SNfMa6Fb0Z sGgM1+9YjaKWQumf3++DOe/zMyk= X-Google-Smtp-Source: ABdhPJx9AF7tORTLtgPQIRGaLKtq7413l8Z76aS59E00uak73td2NPgBTs1wu4w51hdbRBwQ2QC89RE= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:0:7898:24e2:b0bc:77e6]) (user=pcc job=sendgmr) by 2002:a0c:f805:: with SMTP id r5mr15630966qvn.45.1617426816378; Fri, 02 Apr 2021 22:13:36 -0700 (PDT) Date: Fri, 2 Apr 2021 22:13:25 -0700 Message-Id: <20210403051325.683071-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH] kfence: unpoison pool region before use From: Peter Collingbourne To: Marco Elver , Dmitry Vyukov , Alexander Potapenko Cc: Peter Collingbourne , Evgenii Stepanov , Andrey Konovalov , linux-mm@kvack.org, linux-kernel@vger.kernel.org X-Stat-Signature: sxjan67bpawph1ss5b8btjc1msp5pjn5 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0F19FA00038E Received-SPF: none (flex--pcc.bounces.google.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from="<3gPlnYAMKCB0I559HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--pcc.bounces.google.com>"; helo=mail-qt1-f202.google.com; client-ip=209.85.160.202 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617426816-770351 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: If the memory region allocated by KFENCE had previously been poisoned, any validity checks done using kasan_byte_accessible() will fail. Fix it by unpoisoning the memory before using it as the pool region. Link: https://linux-review.googlesource.com/id/I0af99e9f1c25eaf7e1ec295836b5d148d76940c5 Signed-off-by: Peter Collingbourne --- mm/kfence/core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index d53c91f881a4..bb22b0cf77aa 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -633,13 +633,19 @@ static DECLARE_DELAYED_WORK(kfence_timer, toggle_allocation_gate); void __init kfence_alloc_pool(void) { + void *pool; + if (!kfence_sample_interval) return; - __kfence_pool = memblock_alloc(KFENCE_POOL_SIZE, PAGE_SIZE); - - if (!__kfence_pool) + pool = memblock_alloc(KFENCE_POOL_SIZE, PAGE_SIZE); + if (!pool) { pr_err("failed to allocate pool\n"); + return; + } + + kasan_unpoison_range(pool, KFENCE_POOL_SIZE); + __kfence_pool = pool; } void __init kfence_init(void)