Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49F3CC433E2 for ; Thu, 25 Jun 2020 21:56:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0A50420768 for ; Thu, 25 Jun 2020 21:56:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EAX1DJUj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A50420768 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1458A6B0003; Thu, 25 Jun 2020 17:56:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ADB56B0007; Thu, 25 Jun 2020 17:55:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF3E96B0003; Thu, 25 Jun 2020 17:55:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id B92C16B0005 for ; Thu, 25 Jun 2020 17:55:59 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7819B2DFD for ; Thu, 25 Jun 2020 21:55:59 +0000 (UTC) X-FDA: 76969092438.07.rice24_1a14d0b26e50 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 4C7FE1803FD61 for ; Thu, 25 Jun 2020 21:55:59 +0000 (UTC) X-HE-Tag: rice24_1a14d0b26e50 X-Filterd-Recvd-Size: 5543 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Thu, 25 Jun 2020 21:55:58 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id x207so3679250pfc.5 for ; Thu, 25 Jun 2020 14:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7A3ut0s/fDrYdZLuerEwUW8oCMYtKMgoS+BmFPV6E48=; b=EAX1DJUjyWzo+h0AIzexC7N/8D1YSmVHsQR+1EMo5hJkdoOjsTZH71VlIZJq9Ln5v2 4ucz7qrAwno2uZFZm6xgJyccTswpWYnpRoX1HlRBF1jPneET7PwSm/M5sz4YD0b/wptd rw0ky4FI5PBORLUuxCJmyieQ5XMmlBJx+YIt8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7A3ut0s/fDrYdZLuerEwUW8oCMYtKMgoS+BmFPV6E48=; b=n8TX2+gjIgLpvjWt7aWgqF52fE4CY7mjm3FbUKyCA9uSOd75cTj3wP1U95fLuaC6Ve VNr7+lMarmOwPvIGYv5W4t8dpsP869ZP5jrMVoQj4z/dqqOxih2IgSGbPWQM2ok9BSe7 +f7XMaICXMBS/i4XaFJiYmlL3IrCfFK8DxwJ8Y1v67JuROh52iV/cLHjOtofXXjFd/kw sUCeB+F6Jo4WYLsQOLknMeapsCU8mErnmcWDTT5chuTQg2rSfnD1TPnBl1BVMQptCf8X +sXGFy/eQUQy5ZNGC92Nt7JbwZ+TojXH4UFNiuoQdmD91CXi1wREpAvIykHzgnhcK4oh PthA== X-Gm-Message-State: AOAM533yllJJRbJtb2SjqvyNT/l1WUWcqt3k2eYVQJT3TPyV7Ong+Q62 jNjU5xUdfd0bmyVhGEXGYOVO6w== X-Google-Smtp-Source: ABdhPJyhcT2sDKANwEpDmUbojDTCXPEXRrzBTDNJGDiwSiqDtIycN9E7qeWFgne+DnoVmxgF5v59Lw== X-Received: by 2002:a63:5a66:: with SMTP id k38mr27602446pgm.240.1593122158040; Thu, 25 Jun 2020 14:55:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q6sm23425892pff.79.2020.06.25.14.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 14:55:56 -0700 (PDT) From: Kees Cook To: akpm@linux-foundation.org Cc: Kees Cook , Vlastimil Babka , Roman Gushchin , Christoph Lameter , Alexander Popov , Pekka Enberg , David Rientjes , Joonsoo Kim , vinmenon@codeaurora.org, Matthew Garrett , Jann Horn , Vijayanand Jitta , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm: Expand CONFIG_SLAB_FREELIST_HARDENED to include SLAB Date: Thu, 25 Jun 2020 14:55:47 -0700 Message-Id: <20200625215548.389774-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200625215548.389774-1-keescook@chromium.org> References: <20200625215548.389774-1-keescook@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4C7FE1803FD61 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 Content-Transfer-Encoding: quoted-printable 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: Include SLAB caches when performing kmem_cache pointer verification. A defense against such corruption[1] should be applied to all the allocators. With this added, the "SLAB_FREE_CROSS" and "SLAB_FREE_PAGE" LKDTM tests now pass on SLAB: lkdtm: Performing direct entry SLAB_FREE_CROSS lkdtm: Attempting cross-cache slab free ... ------------[ cut here ]------------ cache_from_obj: Wrong slab cache. lkdtm-heap-b but object is from lkdtm= -heap-a WARNING: CPU: 2 PID: 2195 at mm/slab.h:530 kmem_cache_free+0x8d/0x1d0 ... lkdtm: Performing direct entry SLAB_FREE_PAGE lkdtm: Attempting non-Slab slab free ... ------------[ cut here ]------------ virt_to_cache: Object is not a Slab page! WARNING: CPU: 1 PID: 2202 at mm/slab.h:489 kmem_cache_free+0x196/0x1d0 Additionally clean up neighboring Kconfig entries for clarity, readability, and redundant option removal. [1] https://github.com/ThomasKing2014/slides/raw/master/Building%20univer= sal%20Android%20rooting%20with%20a%20type%20confusion%20vulnerability.pdf Fixes: 598a0717a816 ("mm/slab: validate cache membership under freelist h= ardening") Signed-off-by: Kees Cook --- init/Kconfig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index a46aa8f3174d..7542d28c6f61 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1885,9 +1885,8 @@ config SLAB_MERGE_DEFAULT command line. =20 config SLAB_FREELIST_RANDOM - default n + bool "Randomize slab freelist" depends on SLAB || SLUB - bool "SLAB freelist randomization" help Randomizes the freelist order used on creating new pages. This security feature reduces the predictability of the kernel slab @@ -1895,12 +1894,14 @@ config SLAB_FREELIST_RANDOM =20 config SLAB_FREELIST_HARDENED bool "Harden slab freelist metadata" - depends on SLUB + depends on SLAB || SLUB help Many kernel heap attacks try to target slab cache metadata and other infrastructure. This options makes minor performance sacrifices to harden the kernel slab allocator against common - freelist exploit methods. + freelist exploit methods. Some slab implementations have more + sanity-checking than others. This option is most effective with + CONFIG_SLUB. =20 config SHUFFLE_PAGE_ALLOCATOR bool "Page allocator randomization" --=20 2.25.1