From patchwork Mon Oct 21 13:02:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13844268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C369D15D8F for ; Mon, 21 Oct 2024 14:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To: Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=UBVj7hwiJkBfNNbqJ1p90uIKA5IyeuTojXmRSNi2iDM=; b=GV+o2YJofNxAGw aUxIGQ2XGjlsZTQjbAEOMX8uJhWP9tGbGnDiSJrI4tVP8C/Y8fldRV8Nw2Q7kA3Sfqla1/YCewbYg FZZ9pdL0OqYjjr+tHROOfUyOcI3dExZ2UuiRz2AsmWQRXg/yfxf3prBI5umlvBNI88QJb8/0Jv/1T WnYoaWa7hCt9dhI6YOKBF9+0e34QY+dNpAQxSPx98aqE1k9bIjnchb93abozlQ0xx0YuTQnkV15KG hWC6lc7wcZTF2oKgBqLz7gvNV1t4V2Zltq+7V0UhXXAVKhX13N1lKD2aRr87DI+G+/I57RaIEJYWp Y2XGRz34HGRDoPuZIYfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2tQU-00000007ccz-2Mbi; Mon, 21 Oct 2024 14:30:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2s3y-00000007MI7-1gQh for linux-arm-kernel@bombadil.infradead.org; Mon, 21 Oct 2024 13:03:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-Id:Date:Subject:From:Sender:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=UBVj7hwiJkBfNNbqJ1p90uIKA5IyeuTojXmRSNi2iDM=; b=TUMB1kORNZktM/lEDxn/+Sx4s5 TkXD748R9Fo/aGdP5Dlm7n5MFd0REYT2btOG84O0mdlAt/b8RsqgaskM/lLSGXN5HZKsitsYbd7jM UfnkmOdupoyl7Krdskmaogx7s3TETEWZHHoOsvIYLM98k1QRNCNKBadpFlv3Q0KwFD2A4jWUYQb1y 2HHItS4jPxECXeyJbwIAtT6QRqbDzBVjo6/lvA2v/SEPM3Wm1EEmwh6iQ0RT4AMQ9A+8wva4ebQFO GBjbzkknRYh/vUfspsapgs3XpijDIs1v78wtFXqyVCkj8+c1RKN4EW5GO3Npy2R9V9Ww+lbNIyup/ HIg2RYGw==; Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2s3u-00000007wXx-3fFO for linux-arm-kernel@lists.infradead.org; Mon, 21 Oct 2024 13:03:08 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2fb5be4381dso43995141fa.2 for ; Mon, 21 Oct 2024 06:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729515783; x=1730120583; darn=lists.infradead.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=UBVj7hwiJkBfNNbqJ1p90uIKA5IyeuTojXmRSNi2iDM=; b=GuEgFA9CoSXQwS1kl8IFLSL/+RNFjh0S/7EGGJfTm+rZZZANQ6va+c+PHFyQUtGo/t 0oRivJQEsrqOV0PvmiTCA2FlA63sZKgcSpdi5j0VOZCjnlWhLYQo5o3Jhmz1Ia0aVH0v i7DwmDdqm4tLcmFWT8MIG9eeIBplM4XKFPmwVMDYvR54Kvb+lmpG2/8Df8rA2y6PW+zH rYCbYxgug5xo2bDG0vOKBt6Q95a4A52UQAEFHjB9edoFsiEP7hlEH5QiAXCYZ6OvO1Oc 6x+2TYDOW3mksI8Eb5OjlwxOCwhW4hF6Gi5U2M1A9NB32JrX3dSQk+pN06mtMY6B9Hn1 BXuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729515783; x=1730120583; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UBVj7hwiJkBfNNbqJ1p90uIKA5IyeuTojXmRSNi2iDM=; b=NMa9mQOSXH7GbeSu6skOysdjzCROiasfYt5sQ8s74+/MSFmuW1/MMWwJi/at8DxOTd Q7lHqC8IN/Z6xxOnxJSwAH6TKR1rU/IcZXgr2dlTKNUOV6dJTn8eCOkP8iw9DemXbDE5 WInapBva1Vw9sVwwlKOp9eFvrSswhj86irZzzmtQaq99NVbmm57HLH9YfFSRTRKChibG QfNpMS15cFIyLGcs+69rwz0MZoUf5dETmNMCxvxwCDw2wmMpllbcTXQe5bLZ74aUMG8v HMuNvuev1DMFVUS8+djeaZhyAvhwlXH4EaDP7GtxHryTjYk1sBW9oLaOlsBUGVqxB+fs AbrQ== X-Forwarded-Encrypted: i=1; AJvYcCVgcmKWiM9DAb8pImS/EeTXxbsHN63wltJ7/tfESi4FaAqoMgfnPRUVDJAF3MosgmPozG3XxHd6GvQlQLeq9xXV@lists.infradead.org X-Gm-Message-State: AOJu0Yw6Nra0XgIwN7LiUqqyktviG6hBUk1pTKbLiQy5aO/00TDcUfcm 03dILHbdHg3tBUBr5xdZlwtPANcUjrZrujPoN9uQRLCZJqgZs3Z24iKZPV4XMGI= X-Google-Smtp-Source: AGHT+IG8laNr07uMgyvCGL35sCAnuBEi+eOF50gkS3gF675d/DHfKwi5UOYoiwlWGy+RShs73rP5eA== X-Received: by 2002:a2e:998c:0:b0:2fa:bf53:1dad with SMTP id 38308e7fff4ca-2fb83200a44mr42548261fa.31.1729515782691; Mon, 21 Oct 2024 06:03:02 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2fb9ae24d51sm4808351fa.130.2024.10.21.06.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 06:03:02 -0700 (PDT) From: Linus Walleij Subject: [PATCH v4 0/3] Fix KASAN crash when using KASAN_VMALLOC Date: Mon, 21 Oct 2024 15:02:57 +0200 Message-Id: <20241021-arm-kasan-vmalloc-crash-v4-0-837d1294344f@linaro.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAFRFmcC/4XOTQ6CMBAF4KuQrq3pP+jKexgXQ1ugEahpTaMh3 N3CCmOIyzfJfO9NKNrgbETnYkLBJhedH3MQhwLpDsbWYmdyRowwQQmVGMKA7xBhxGmAvvca6wC xw42ujaSCKiFLlL8fwTbutcrXW86di08f3mtRosv1v5koJtjUNePyxDRU/NK7EYI/+tCiBU1sC 6l9iGWIgGSNIZWytvmB+BYq9yG+LGLAhTayVup70TzPH1eO/RxRAQAA To: Clement LE GOFFIC , Russell King , Melon Liu , Kees Cook , AngeloGioacchino Del Regno , Mark Brown , Mark Rutland , Ard Biesheuvel Cc: Antonio Borneo , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Linus Walleij , stable@vger.kernel.org X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_140307_098730_21C3C1DA X-CRM114-Status: GOOD ( 15.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This problem reported by Clement LE GOFFIC manifest when using CONFIG_KASAN_IN_VMALLOC and VMAP_STACK: https://lore.kernel.org/linux-arm-kernel/a1a1d062-f3a2-4d05-9836-3b098de9db6d@foss.st.com/ After some analysis it seems we are missing to sync the VMALLOC shadow memory in top level PGD to all CPUs. Add some code to perform this sync, and the bug appears to go away. As suggested by Ard, also perform a dummy read from the shadow memory of the new VMAP_STACK in the low level assembly. Signed-off-by: Linus Walleij --- Changes in v4: - Since Kasan is not using header stubs, it is necessary to avoid kasan_*() calls using ifdef when compiling without KASAN. - Lift a line aligning the end of vmalloc from Melon Liu's very similar patch so we have feature parity, credit Melon as co-developer. - Include the atomic_read_acquire() patch in the series due to context requirements. - Verify that the after the patch the kernel still builds and boots without Kasan. - Link to v3: https://lore.kernel.org/r/20241017-arm-kasan-vmalloc-crash-v3-0-d2a34cd5b663@linaro.org Changes in v3: - Collect Mark Rutlands ACK on patch 1 - Change the simplified assembly add r2, ip, lsr #n to the canonical add r2, r2, ip, lsr #n in patch 2. - Link to v2: https://lore.kernel.org/r/20241016-arm-kasan-vmalloc-crash-v2-0-0a52fd086eef@linaro.org Changes in v2: - Implement the two helper functions suggested by Russell making the KASAN PGD copying less messy. - Link to v1: https://lore.kernel.org/r/20241015-arm-kasan-vmalloc-crash-v1-0-dbb23592ca83@linaro.org --- Linus Walleij (3): ARM: ioremap: Sync PGDs for VMALLOC shadow ARM: entry: Do a dummy read from VMAP shadow mm: Pair atomic_set_release() with _read_acquire() arch/arm/kernel/entry-armv.S | 8 ++++++++ arch/arm/mm/ioremap.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) --- base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc change-id: 20241015-arm-kasan-vmalloc-crash-fcbd51416457 Best regards,