From patchwork Wed Feb 28 12:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 129978 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp952973lja; Wed, 28 Feb 2018 04:15:17 -0800 (PST) X-Google-Smtp-Source: AH8x225ZcyzkBruRGfyad+qH9547OU46bouKm7xg12/K66aeqQi8SGePKQaQn9of3KlE0+IxZbtW X-Received: by 10.99.7.15 with SMTP id 15mr13615641pgh.388.1519820117810; Wed, 28 Feb 2018 04:15:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519820117; cv=none; d=google.com; s=arc-20160816; b=N4tEFciF9pYphcCFKXxmcK+Z7FMsFnLOEQ5HxxmyB0hYR6QDgVB4/y+6d5gPBBm1VV uK2T9FH41rKa/2Ezrr+E4GNq+B4ADaIut+4Hpsz1kaXE4nSdjmfpLkVNCtT1ED7WXG2K 3ASXwzSWJMhjjfv3HvAfYxg/NFhVPzZEA0swhGjM5X2zWmmjdfVCndPo/hnp9Vx3HaXU 6jNb7eXkY25TO3XobTPVyEEXKd+0ofhfuHvxJYOC/zEkpfehDVFmA7bvwu6B+h4yXMRQ OGbg9904SKdpZ8/VMjZeZIZV191SGmmxko0+nSLyow1OmN3l8WfV418tKe9bOESFcsmJ 0RGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JzNYOezdyNgiPm8Ia7ABEe6rFRYOgXYX3QGUdaxJYAY=; b=ulGb6NfFBP+Qrl/ZqT7cr7oc/dIBAdcmGrx4UXFZu5khhjW0zZvk2sdIRKZNpOWQ4H 1NS11ojzuXRz2flLQp7eBpfhikrcO40ddpw3PoJWQnc2K2SC2x4z87WWvZaxhb/QVVlu 0fWwvGlloYn/I/cCVKJslQkHFdljkqQUsQqT6TwmalQ5gEBipIr0H78IQwZOY+/QyHPr sSI+6LeHU9Qjk63AbL5RQh6rc7h4fFTgU6Bi3jR1ApdVI9yQemfUQN00tJdy6Jbtyizl VMo35PfCPKzM6UBlZn3P55TGRM31ac1iK10sTMxIHh3bUfaQ6qxPmb8bjCmEl6nCNnKX d7KA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si1192498plr.786.2018.02.28.04.15.17; Wed, 28 Feb 2018 04:15:17 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbeB1MPO (ORCPT + 28 others); Wed, 28 Feb 2018 07:15:14 -0500 Received: from foss.arm.com ([217.140.101.70]:48536 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbeB1MPN (ORCPT ); Wed, 28 Feb 2018 07:15:13 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6C5115AD; Wed, 28 Feb 2018 04:15:12 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3863C3F487; Wed, 28 Feb 2018 04:15:11 -0800 (PST) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Andrew Morton , Ingo Molnar , Mathieu Desnoyers , Michal Hocko , Peter Zijlstra , Rik van Riel , Will Deacon Subject: [PATCH] Detect early free of a live mm Date: Wed, 28 Feb 2018 12:14:58 +0000 Message-Id: <20180228121458.2230-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KASAN splats indicate that in some cases we free a live mm, then continue to access it, with potentially disastrous results. This is likely due to a mismatched mmdrop() somewhere in the kernel, but so far the culprit remains elusive. Let's have __mmdrop() verify that the mm isn't live for the current task, similar to the existing check for init_mm. This way, we can catch this class of issue earlier, and without requiring KASAN. Signed-off-by: Mark Rutland Cc: Andrew Morton Cc: Ingo Molnar Cc: Mathieu Desnoyers Cc: Michal Hocko Cc: Peter Zijlstra Cc: Rik van Riel Cc: Will Deacon --- kernel/fork.c | 2 ++ 1 file changed, 2 insertions(+) Hi, For context, we're seeing an intermittent use-after-free of an mm on arm64 [1], where it looks like an mm has been freed earlier than expected. So far KASAN has only caught legitimate mmdrop() uses, where mm_count is presumably already bogus. Mark. [1] https://lkml.kernel.org/r/20180214120254.qq4w4s42ecxio7lu@lakrids.cambridge.arm.com -- 2.11.0 diff --git a/kernel/fork.c b/kernel/fork.c index e5d9d405ae4e..6922d93551b8 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -595,6 +595,8 @@ static void check_mm(struct mm_struct *mm) void __mmdrop(struct mm_struct *mm) { BUG_ON(mm == &init_mm); + BUG_ON(mm == current->mm); + BUG_ON(mm == current->active_mm); mm_free_pgd(mm); destroy_context(mm); hmm_mm_destroy(mm);