Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp520495yba; Wed, 24 Apr 2019 05:26:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWmHyVsc6IA7WJl45oVhfu/oLZZILBwT5/zOqyZ6tlcda6juN258mAvDMDz4Hvy+rGhoZU X-Received: by 2002:a05:6a00:11:: with SMTP id h17mr32828741pfk.232.1556108805594; Wed, 24 Apr 2019 05:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556108805; cv=none; d=google.com; s=arc-20160816; b=n5TGfWJEcmYqjZqpapmnX0riiJUoWWerk7Cbt1+K//rf6EMznEfENUakcP8abBC/ez +jbE7KJNSn0ssXN4aOf/LGZm+pTutbGceoYVjtpgaRojLD7+QxaTZrQVYmlOAJlqNSgA xWgj0VyP9JhAMfqKjx1SuCYvT0oFoAi8L/ikQ/qktdTDsL1Eg3opplGFUJtGBia8mEBS ES1P87OznQgVEOtYPibwqAHn3mR2iSlnAEiqGl7C17z/qoHOPDtA/YezQ10hh5yxxhGu MJYn2UB3QDbN9pfkgPVDBKxfXJSLz0GicIRcTOMfpht4ZALOndWNldYnJ3utJf655cVE Cxyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lUulz3WEVwTPVcIBrDn+6iWulfPqFeqv7zmMaO4tAko=; b=XCy1m35JUqdHjx4iglfnvkk6jl/c1KJWwg9kc7cGIgR9c5tD1chXQC+/ZMrlEaxURb 9KMYHGl7jhBTNG1Tn3Of5WrBeShwNJgBbJ40dKA/bt43hT4uBWmchMxlzLro+LK1Hi4u n2V3ZdS2TCTgS7ZulJp8+rMxcXa0nXKYYYMq/vF+MCcRnxSG83B4WX2qg2/1bqOvSkKx ik/WkLTThZIQ8VA9ASLISc/W8/NJnIWSC9rotV5aZOhQG8WFHXsfkNR4EEaLxspQdAMe +j3b9k9UmNnjyne35Z/D5+cKS4kpFAZ10yrVBeposU3tnbYf89u8vUaZDvk2QAmBmRip KR/g== 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 60si18783497pla.335.2019.04.24.05.26.30; Wed, 24 Apr 2019 05:26:45 -0700 (PDT) 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 S1729759AbfDXMY4 (ORCPT + 99 others); Wed, 24 Apr 2019 08:24:56 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42568 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbfDXMYz (ORCPT ); Wed, 24 Apr 2019 08:24:55 -0400 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 7FCD7A78; Wed, 24 Apr 2019 05:24:55 -0700 (PDT) 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 ESMTPSA id 659603F238; Wed, 24 Apr 2019 05:24:54 -0700 (PDT) Date: Wed, 24 Apr 2019 13:24:51 +0100 From: Mark Rutland To: Weikang shi Cc: keescook@chromium.org, arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] lkdtm: fix potential use after free Message-ID: <20190424122451.GC24502@lakrids.cambridge.arm.com> References: <20190424102103.11816-1-swkhack@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190424102103.11816-1-swkhack@gmail.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 24, 2019 at 06:21:03PM +0800, Weikang shi wrote: > From: swkhack > > The function lkdtm_WRITE_AFTER_FREE calls kfree(base) to free the memory > of base. However, following kfree(base), > it write the memory which base point to via base[offset] = 0x0abcdef0. This may result in a > use-after-free bug. This patch moves kfree(base) after the write. As with lkdtm_READ_AFTER_FREE, this is deliberate, and we should not make this change. Thanks, Mark. > > Signed-off-by: swkhack > --- > drivers/misc/lkdtm/heap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c > index 65026d7de..0b9141525 100644 > --- a/drivers/misc/lkdtm/heap.c > +++ b/drivers/misc/lkdtm/heap.c > @@ -40,8 +40,8 @@ void lkdtm_WRITE_AFTER_FREE(void) > pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]); > pr_info("Attempting bad write to freed memory at %p\n", > &base[offset]); > - kfree(base); > base[offset] = 0x0abcdef0; > + kfree(base); > /* Attempt to notice the overwrite. */ > again = kmalloc(len, GFP_KERNEL); > kfree(again); > -- > 2.17.1 >