Message ID | 202003051623.AF4F8CB@keescook (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <SRS0=5Xj8=4X=kvack.org=owner-linux-mm@kernel.org> Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CEAD92A for <patchwork-linux-mm@patchwork.kernel.org>; Fri, 6 Mar 2020 00:24:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 483E220717 for <patchwork-linux-mm@patchwork.kernel.org>; Fri, 6 Mar 2020 00:24:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fauVLb+m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 483E220717 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 87D1D6B0005; Thu, 5 Mar 2020 19:24:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 853B16B0006; Thu, 5 Mar 2020 19:24:32 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76A3F6B0007; Thu, 5 Mar 2020 19:24:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 5F6D06B0005 for <linux-mm@kvack.org>; Thu, 5 Mar 2020 19:24:32 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1FF1E180AD801 for <linux-mm@kvack.org>; Fri, 6 Mar 2020 00:24:32 +0000 (UTC) X-FDA: 76563041184.16.cake26_278eee424120a X-Spam-Summary: 50,0,0,9106497de3cbfca7,d41d8cd98f00b204,keescook@chromium.org,,RULES_HIT:41:355:379:800:960:965:966:967:973:988:989:1260:1277:1312:1313:1314:1345:1437:1516:1518:1519:1535:1542:1593:1594:1595:1596:1711:1730:1747:1777:1792:2196:2197:2199:2200:2393:2525:2560:2563:2682:2685:2739:2859:2933:2937:2939:2942:2945:2947:2951:2954:3000:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4390:4395:4605:5007:6117:6119:6120:6261:6653:6691:7514:7901:7903:8660:9010:9025:9121:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12903:13148:13161:13221:13229:13230:13439:13895:14096:14097:14181:14394:14721:21080:21220:21444:21451:21611:21627:21990:30003:30034:30054,0,RBL:209.85.210.194:@chromium.org:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_ru les:0:0: X-HE-Tag: cake26_278eee424120a X-Filterd-Recvd-Size: 5086 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf33.hostedemail.com (Postfix) with ESMTP for <linux-mm@kvack.org>; Fri, 6 Mar 2020 00:24:31 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id l184so191686pfl.7 for <linux-mm@kvack.org>; Thu, 05 Mar 2020 16:24:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=xRy9hgdRfr2pI2+j3xM5QiyuXkfsaYppAUVWfvsGN38=; b=fauVLb+mmzDkXqeR0x5V4vpTs+F8Fsi7S5j+semYUBkPjjZqFQrMg2Vy2/IPU9Ntvy 6zz/ISIr18Fba0M1h/D4bqPBJ2aEY1w6Bf9pPuDxlUWRu1MaHnSnI63ocRr8O7QRpgOS ULYlBRs04rLMiXN3rfmq91GijGBxNHzll4agw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=xRy9hgdRfr2pI2+j3xM5QiyuXkfsaYppAUVWfvsGN38=; b=V6KD9T475VLQ1QZFwoG89X8bEqbRo1QyYAdqCJq8VX/kWDdoNQv1PKXWsXBoapbDeg TB9WiXP4XJ70iEjltIeQE5MSaaJDxYldnQfUEbUspzz/88/PDq9Reh8Vx1ibYVtaUm8p hpk6OxtRCDytWLbNwasdL4PDu5JbBeqhz9++KVjBFVFY9Ddq663FzgeirKr0CfDLg/QN tjePth7A80xWGC8AxxNjm2Iw2yTHpIjZZk7ewfMcvCcCG7aLBzMsO2K94j7/oe8CpDhE Q09Cy1MB0llZnkdU0UeYEyDndUoK2YCHTraFuu7bojqIgNavI/cbBzJD0GpxdUNNSfPM rgig== X-Gm-Message-State: ANhLgQ2DqFqbEWDDfN33oYMjf575SP6TWXpoDKUjx4f2IIwrGJGJU56V dIfQn06NizDp8bj40ISHnDngSQ== X-Google-Smtp-Source: ADFU+vvCgOtnmu5BVGxMSLqbNh9JOZ7MZpYoz/vRPGo0pl2lLbg7DmsarwvLoFafJnbWFmTbFUGL5Q== X-Received: by 2002:aa7:87d4:: with SMTP id i20mr972175pfo.22.1583454270564; Thu, 05 Mar 2020 16:24:30 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w2sm25298002pfb.138.2020.03.05.16.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 16:24:29 -0800 (PST) Date: Thu, 5 Mar 2020 16:24:28 -0800 From: Kees Cook <keescook@chromium.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Christoph Lameter <cl@linux.com>, Pekka Enberg <penberg@kernel.org>, David Rientjes <rientjes@google.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com>, Daniel Micay <danielmicay@gmail.com>, Silvio Cesare <silvio.cesare@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] slub: Improve bit diffusion for freelist ptr obfuscation Message-ID: <202003051623.AF4F8CB@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: <linux-mm.kvack.org> |
Series |
slub: Improve bit diffusion for freelist ptr obfuscation
|
expand
|
diff --git a/mm/slub.c b/mm/slub.c index 17dc00e33115..107d9d89cf96 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -259,7 +259,7 @@ static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr, * freepointer to be restored incorrectly. */ return (void *)((unsigned long)ptr ^ s->random ^ - (unsigned long)kasan_reset_tag((void *)ptr_addr)); + swab((unsigned long)kasan_reset_tag((void *)ptr_addr))); #else return ptr; #endif
Under CONFIG_SLAB_FREELIST_HARDENED=y, the obfuscation was relatively weak in that the ptr and ptr address were usually so close that the first XOR would result in an almost entirely 0-byte value[1], leaving most of the "secret" number ultimately being stored after the third XOR. A single blind memory content exposure of the freelist was generally sufficient to learn the secret. Add a swab() call to mix bits a little more. This is a cheap way (1 cycle) to make attacks need more than a single exposure to learn the secret (or to know _where_ the exposure is in memory). kmalloc-32 freelist walk, before: ptr ptr_addr stored value secret ffff90c22e019020@ffff90c22e019000 is 86528eb656b3b5bd (86528eb656b3b59d) ffff90c22e019040@ffff90c22e019020 is 86528eb656b3b5fd (86528eb656b3b59d) ffff90c22e019060@ffff90c22e019040 is 86528eb656b3b5bd (86528eb656b3b59d) ffff90c22e019080@ffff90c22e019060 is 86528eb656b3b57d (86528eb656b3b59d) ffff90c22e0190a0@ffff90c22e019080 is 86528eb656b3b5bd (86528eb656b3b59d) ... after: ptr ptr_addr stored value secret ffff9eed6e019020@ffff9eed6e019000 is 793d1135d52cda42 (86528eb656b3b59d) ffff9eed6e019040@ffff9eed6e019020 is 593d1135d52cda22 (86528eb656b3b59d) ffff9eed6e019060@ffff9eed6e019040 is 393d1135d52cda02 (86528eb656b3b59d) ffff9eed6e019080@ffff9eed6e019060 is 193d1135d52cdae2 (86528eb656b3b59d) ffff9eed6e0190a0@ffff9eed6e019080 is f93d1135d52cdac2 (86528eb656b3b59d) [1] https://blog.infosectcbr.com.au/2020/03/weaknesses-in-linux-kernel-heap.html Reported-by: Silvio Cesare <silvio.cesare@gmail.com> Fixes: 2482ddec670f ("mm: add SLUB free list pointer obfuscation") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> --- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)