From patchwork Fri Aug 11 16:17:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 9896273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4551560351 for ; Fri, 11 Aug 2017 16:18:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37BBD28C35 for ; Fri, 11 Aug 2017 16:18:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C42D28C45; Fri, 11 Aug 2017 16:18:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 6EFE228C35 for ; Fri, 11 Aug 2017 16:18:01 +0000 (UTC) Received: (qmail 10066 invoked by uid 550); 11 Aug 2017 16:17:47 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 10032 invoked from network); 11 Aug 2017 16:17:46 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=LtleAciqX1pBx/+tXDbYKA3saipDtTLetbYoMOnWuiU=; b=nYsKRNTrR5zs57Z34WGaNp8hWfwNg+epqAeBAbzmk17bJykQSWYP3SLdVfomNEGdSx j9mAKv71Gx3Fl+laJxfXLa4p3p4CL9jlto88r1ZTXpmR/aIIs9Nvedzlpj2Ulxn315fk tapVpc7DXr4HgcMozWRa8hdUh9N0aYl2DiT0kunta/2OdLQ69G+KA0SLKlgIp95dtmPf u+k65xk5vwgtiGjS3qNXV7HopuulqTSoEMtFPSsaLx/nvtlADBSvrBQU934ViMSPvjGo auAhjTw7BmBJ6j5MClaHYqY2YhUUi4Vc7r8acofp/X+4XWjIk9BYtamBolshPuVLW1Pi XbOw== X-Gm-Message-State: AHYfb5hhyVFHR56W2zKAlLHgwq3FunZBI6k774VMRzNMVhAIN7dsVMTi EW2REHZdQ0m6yg== X-Received: by 10.25.181.150 with SMTP id g22mr3484078lfk.128.1502468255693; Fri, 11 Aug 2017 09:17:35 -0700 (PDT) From: Alexander Popov To: Kees Cook , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Paul E McKenney , Ingo Molnar , Tejun Heo , Andy Lutomirski , Nicolas Pitre , linux-mm@kvack.org, Rik van Riel , Tycho Andersen , Alexander Popov , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Fri, 11 Aug 2017 19:17:26 +0300 Message-Id: <1502468246-1262-1-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [linux-next][PATCH v2] mm/slub.c: add a naive detection of double free or corruption X-Virus-Scanned: ClamAV using ClamSMTP Add an assertion similar to "fasttop" check in GNU C Library allocator as a part of SLAB_FREELIST_HARDENED feature. An object added to a singly linked freelist should not point to itself. That helps to detect some double free errors (e.g. CVE-2017-2636) without slub_debug and KASAN. Signed-off-by: Alexander Popov Acked-by: Christoph Lameter --- mm/slub.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index b9c7f1a..77b2781 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -290,6 +290,10 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp) { unsigned long freeptr_addr = (unsigned long)object + s->offset; +#ifdef CONFIG_SLAB_FREELIST_HARDENED + BUG_ON(object == fp); /* naive detection of double free or corruption */ +#endif + *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr); }