From patchwork Mon Nov 23 20:07:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926419 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=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 DE5B7C2D0E4 for ; Mon, 23 Nov 2020 20:09:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 59B7D20715 for ; Mon, 23 Nov 2020 20:09:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vkxW6RZN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59B7D20715 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 1CCA96B00B5; Mon, 23 Nov 2020 15:09:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 156446B00B6; Mon, 23 Nov 2020 15:09:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01DC26B00B7; Mon, 23 Nov 2020 15:09:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0142.hostedemail.com [216.40.44.142]) by kanga.kvack.org (Postfix) with ESMTP id C37AF6B00B5 for ; Mon, 23 Nov 2020 15:09:42 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5307C363D for ; Mon, 23 Nov 2020 20:09:42 +0000 (UTC) X-FDA: 77516773404.24.cord23_130138e27368 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 342511A4AA for ; Mon, 23 Nov 2020 20:09:42 +0000 (UTC) X-HE-Tag: cord23_130138e27368 X-Filterd-Recvd-Size: 4655 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 20:09:41 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id a22so5032152qtx.20 for ; Mon, 23 Nov 2020 12:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=JqOdOudIAs6fCsGoOMJBOXRAJ4nBM51Q9IuLvpe9X7o=; b=vkxW6RZNeiKt3uDXc9cHATR3yMNcOPJqStPkUehbC/zuvJcXUjcLUlqnCHiChMMXOM c71zmtYoiGl5xy8iIG7mT1M1VQucOQvK1LAC5ywznp2VK69TDjuYjE4jSsbKaRpiUm8y sM6M/LJaplFV13/x/OJvNqf/icVGsPo2tG/Lf+RwL6jkzxr7ofjAqqsanPWI677zjgYP lbRjaTr3RXJWAWEbSbifTQIYdzFOZ9607IvrKeoWsbPXMOJQyh/MOW++TV1RAnTyiBD0 rGAzeg91KocpdVKgKspqM96WumykTFfRxbnrlu4hk2QablCk2YfVGGBB8TQ2fNZAYkRT bJOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JqOdOudIAs6fCsGoOMJBOXRAJ4nBM51Q9IuLvpe9X7o=; b=H315D87h6Begjl3xW9eP/CBeDYYZ5ZdkPk9FxKyDWlm4qKItFa/T6oPM/f1tKFIQ7/ xrC9sAxd/3V1UBxzLAxFHIVAB6MAGApCKfDIfwXore4LrcRIj/Vl5cD3knPTgda2FBMz 1xwk+93acGci51DFCZT9IBSG/viSlR3FcvI/h/BHYC9ZUOw3/P9hgdPii3plg+UczKsT 1E/e8MwIkUfwyQV0HZuaGVn6uyscCHUqcK3/2kiXKwHxg+mZV4aw0wln5DjkQWF+pKZl fReP9WUn/k4bmg41mjiKfclweUFAs1Fd65EKna7Ogdwb4oc++oKzbybiLd2R5Olj81Xo UyZA== X-Gm-Message-State: AOAM533KnugOlkef8lria1ykfSvykStCDA5z8Pid6MjSU2lf4itCC0qs nYmYU0HOzEwgt3zRx8g9B2Y+m+mOPpbtR7y1 X-Google-Smtp-Source: ABdhPJw73/jwZg0RlewlvU4441kNk0gTp+b0T2ipYrKP6rHNENxFPnemmxMhgs3u5M7bN/vqoeTq/VUwN6Xwbz1I X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:a8f:: with SMTP id ev15mr1201051qvb.20.1606162180614; Mon, 23 Nov 2020 12:09:40 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:55 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 31/42] kasan, mm: untag page address in free_reserved_area From: Andrey Konovalov To: Andrew Morton Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: From: Vincenzo Frascino free_reserved_area() memsets the pages belonging to a given memory area. As that memory hasn't been allocated via page_alloc, the KASAN tags that those pages have are 0x00. As the result the memset might result in a tag mismatch. Untag the address to avoid spurious faults. Cc: Andrew Morton Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- Change-Id: If12b4944383575b8bbd7d971decbd7f04be6748b --- mm/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 42c32e8a9c5d..236aa4b6b2cc 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7659,6 +7659,11 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char * alias for the memset(). */ direct_map_addr = page_address(page); + /* + * Perform a kasan-unchecked memset() since this memory + * has not been initialized. + */ + direct_map_addr = kasan_reset_tag(direct_map_addr); if ((unsigned int)poison <= 0xFF) memset(direct_map_addr, poison, PAGE_SIZE);