From patchwork Thu Dec 15 16:02:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13074311 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 321D3C4332F for ; Thu, 15 Dec 2022 16:03:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68D408E0005; Thu, 15 Dec 2022 11:03:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63CC98E0002; Thu, 15 Dec 2022 11:03:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DDE58E0005; Thu, 15 Dec 2022 11:03:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3D4238E0003 for ; Thu, 15 Dec 2022 11:03:19 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D868880F9D for ; Thu, 15 Dec 2022 16:03:18 +0000 (UTC) X-FDA: 80245010076.05.5051CC3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 21E28A0061 for ; Thu, 15 Dec 2022 16:03:14 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LDa2qZiJ; spf=pass (imf15.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671120195; a=rsa-sha256; cv=none; b=327PgKYrROIqCa5APp435ZVUIM+nEUiob2unPhGI4EW2O/KlGq2dIX8fbZQL4kH3g8IwQP x/iMtdtgx5Ovz6+WhEdA2EqHa9tuihlv2JpLlyxxudw/WR0YupDpI52l5Is0jRPiro1/G4 O79IiLwRFCbk6WruHZxL7UoDLnYnZsU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LDa2qZiJ; spf=pass (imf15.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671120195; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=wHW291lHqyZueeOZojJhSJ9Wkscs64vZJ6pNmv0fUDk=; b=p00tE3QdZz7B2yf3Qw9Pf75UhPehQQ6nifhWKOFwspQla+56N9cx6h5/FAJ7RQbUOye18M 01/1dgqXkbtJ5JrF5jZx0jI0P6yH9wxY3YXeSpyfo9LF/ZV7rP3f4NvbI5WsL0RBDm7SpG xIop7zjLJncbO1E4EiTAjFk72AFM+/c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671120193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wHW291lHqyZueeOZojJhSJ9Wkscs64vZJ6pNmv0fUDk=; b=LDa2qZiJ2XJiP8MgUZDI+XToEVDejg/FRVh095NoIr032SugtswPRWtkywJiq1BmRr64NW Pw/Bk53P19v5rOBLBjUCvh4wxRwi0MPzdw5fNTGUgvVxlkYGaYnFYLR6iPS3Xxp1h2YOm+ h8q7cFW6kcVxOyhxRIFjaML4G2TJcZU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-UV1-hDmNP22VFnpWwnjtpA-1; Thu, 15 Dec 2022 11:03:09 -0500 X-MC-Unique: UV1-hDmNP22VFnpWwnjtpA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 97D28858F09; Thu, 15 Dec 2022 16:03:08 +0000 (UTC) Received: from llong.com (unknown [10.22.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 184C24085721; Thu, 15 Dec 2022 16:03:08 +0000 (UTC) From: Waiman Long To: Catalin Marinas , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Waiman Long Subject: [PATCH v2 0/2] mm/kmemleak: Simplify kmemleak_cond_resched() & fix UAF Date: Thu, 15 Dec 2022 11:02:57 -0500 Message-Id: <20221215160259.261136-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 21E28A0061 X-Stat-Signature: wxca7wq3jghjz1qkgoeocmu3wa1ex85t X-HE-Tag: 1671120194-642525 X-HE-Meta: U2FsdGVkX18Q+Sr6ARDTMUZywQvCyxSvXC2b5bg7eazL6IJm4bvmALyuXkVFsg68BfHzZC+7D/iDdqEgK+KwwuMVdgXhz4ZZ4aGzUxVGpsQGAHcrAmenGxIUXAR5LbqmPg7J0od5O4K7IyAKq9Qrzy34qzT3ppwN0NVX6RyOGhKjly57N7httcbm42k0E5kR/UH5h4ol5Tw9jG7KM0AvaVYE5ub3vrI5KVT7uhP2EXAGwaFnlicxHy+bPyp5gDWNEYALGi8yVCbzi6dvoF19NGRCcrCv9+qL6ZtfckTyn+6KEtETlZQwS4b3C4FyRptQi6gBL5XwBQ7b3jEd2prjn9xBEwdi840/s0SZd8Jh+vbLtF+eKNpEIHo/8gY9rkI4DJxgiANdMhvAru71+A/Hc0ME/6v0VyNCNlbXTXkJI9KtIFs8cjM4ozAaVmpgmGJcjosCxcdUiEMEBdaujrS8OUwhWfpUAmiwkpqD4pMmjrYcfb50ay8lSMpgMFdlQl3/ul9W7wUXXv/sBfGQURD7OlKytDvf43nv59kH8XhdoZyFJw1RKO0rRa3EwNxnSQAVQ4R7N7eTy0m4a9njeGs8FMQTkcQmcQixcCdjoM6wifaVx2tIFjFXRY+IfAt/9IR1eHq9/8OP7AiNlK5PPbrFw6118aoIKEvgTNPkbfwObH0Eo08Y3z9i3w6ZIximjZ4eU7ACLxjiJKQAHdXql8O3zZz7Sfd0neclt2KSzAqFnfKWvpSa+O7swKn5mNH0hQo2X+jrjIRh4HSNqtj5Cpah0I4q2VC6WU+SfSPuih8jX+brGMveuLSf7GqTy3hvjh0WhZBzHK6X3xJeqqwWolqV/g/IrALNjoBLe9buMcjRMBqsQIC75K4zALHMTNt+Q64mtGUlCKcqMFj7kEw55KJoFbMp8rv+SZznE2cf/CbvqLMmRs/okczLk/d/zGTTuaS3AoLFbsaSdfg= 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: It was found that a KASAN use-after-free error was reported in the kmemleak_scan() function. After further examination, it is believe that even though a reference is taken from the current object, it does not prevent the object pointed to by the next pointer from going away after a cond_resched(). To fix that, additional flags are added to make sure that the current object won't be removed from the object_list during the duration of the cond_resched() to ensure the validity of the next pointer. While making the change, I also simplify the current usage of kmemleak_cond_resched() to make it easier to understand. Waiman Long (2): mm/kmemleak: Simplify kmemleak_cond_resched() usage mm/kmemleak: Fix UAF bug in kmemleak_scan() [v2: Update patch 2 to prevent object_list removal of current object] mm/kmemleak.c | 83 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 42 deletions(-)