From patchwork Fri Jun 26 20:07:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11628603 Return-Path: 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 BD17392A for ; Fri, 26 Jun 2020 20:08:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8AB502075D for ; Fri, 26 Jun 2020 20:08:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="O1o8GaHM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AB502075D 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 A07576B0005; Fri, 26 Jun 2020 16:08:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9902E6B0006; Fri, 26 Jun 2020 16:08:02 -0400 (EDT) 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 858626B0007; Fri, 26 Jun 2020 16:08:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 6D8F76B0005 for ; Fri, 26 Jun 2020 16:08:02 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 13C9A180AD806 for ; Fri, 26 Jun 2020 20:08:02 +0000 (UTC) X-FDA: 76972449204.06.price95_1c1573f26e58 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id E720B100470F6 for ; Fri, 26 Jun 2020 20:07:56 +0000 (UTC) X-Spam-Summary: 1,0,0,dd6641225dab79e3,d41d8cd98f00b204,keescook@chromium.org,,RULES_HIT:41:69:355:379:800:960:965:966:967:973:988:989:1260:1277:1312:1313:1314:1345:1437:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4385:4390:4395:5007:6261:6653:7903:9025:9592:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13069:13161:13221:13229:13311:13357:13439:13846:13895:14181:14394:14721:21080:21444:21451:21627:21939:21990:30054,0,RBL:209.85.210.196:@chromium.org:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yrbjrq5xxrj9n7jf3tdn4un1namopz3xnciqwmozihorjop8hq34wi5x4fti6.1wp57ysadfa4knuu98fhadrup5d8rzje7uban6tchqougebzu9cnrfbte1hr9y3.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,Domain Cache:0, X-HE-Tag: price95_1c1573f26e58 X-Filterd-Recvd-Size: 4312 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 26 Jun 2020 20:07:56 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j1so5084363pfe.4 for ; Fri, 26 Jun 2020 13:07:56 -0700 (PDT) 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=rHOsQnFow9W840xshXf2xfNnPEJVNN56X5OCKvatOzc=; b=O1o8GaHMP5dsVMNrT+KaSdj+Cb9ib0h6L+CH70DoWS18/VdJXbuH3MqWxoarxbltgf 9hqSJ7UZ0CHVc+r7XcLBCbzl4RMaKaTYV2GzT8d7aP5yg1A2C4iPLgzgAx6iszB9UWWq 7bLvYkt1y57I9p+8bV+wJcxmRsOeoHMBs0tZY= 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=rHOsQnFow9W840xshXf2xfNnPEJVNN56X5OCKvatOzc=; b=DL/BLta6z2OotyfAfi8T4JM2gjAFPs+ydNmBM9S9zl/6VRTgJylQYdYAxBkCYMOyhN lrzmuAtC7vA1vJ0Y/+CwyWM2+VunG2W9+wfcsuJh1MBExEKZrZLoxbhxEW1NTsmSKWgl GanAEiAODcpCvm04ycnsU69R7zp1K0lueusVIPyUI/OqVqVDx52dMi3opCJStgQCHQYp BgwR4hy84l+/56MuCycBJGkCNTcT6hnIHGzlLA2YCHnEMd7wLk9DzgPam1b8igSLEtol usbK2Q90bmgEcI98N3IdyZoRGvthNtSq8ffI1YP9lbVOTl3Qa5mrypvgLf4PLSr9ri6L rPPQ== X-Gm-Message-State: AOAM532JX3ImAGA7wLOCyH+dVsON9h3u6FYigWVhI1xxrLMp0ZCH7I/T /1Eu7ff5mXGNju7aAkp3Yc1RvQ== X-Google-Smtp-Source: ABdhPJzhZjWKtrGEMaI8byUSdrVEOM1KRfW4lUX66uoeR6p2vSSKp4YijRN8kDnSI5dkSRP37/P6Cw== X-Received: by 2002:aa7:8c03:: with SMTP id c3mr4048300pfd.77.1593202075575; Fri, 26 Jun 2020 13:07:55 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n1sm12409458pjn.24.2020.06.26.13.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 13:07:54 -0700 (PDT) Date: Fri, 26 Jun 2020 13:07:53 -0700 From: Kees Cook To: akpm@linux-foundation.org Cc: Randy Dunlap , broonie@kernel.org, mhocko@suse.cz, sfr@canb.auug.org.au, linux-next@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org Subject: [PATCH] slab: Fix misplaced __free_one() Message-ID: <202006261306.0D82A2B@keescook> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: E720B100470F6 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: The implementation of __free_one() was accidentally placed inside a CONFIG_NUMA #ifdef. Move it above. Reported-by: Randy Dunlap Link: https://lore.kernel.org/lkml/7ff248c7-d447-340c-a8e2-8c02972aca70@infradead.org Signed-off-by: Kees Cook Acked-by: Randy Dunlap # build-tested --- This a fix for slab-add-naive-detection-of-double-free.patch --- mm/slab.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index bbff6705ab2b..5ccb151a6e8f 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -588,6 +588,16 @@ static int transfer_objects(struct array_cache *to, return nr; } +/* &alien->lock must be held by alien callers. */ +static __always_inline void __free_one(struct array_cache *ac, void *objp) +{ + /* Avoid trivial double-free. */ + if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) && + WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp)) + return; + ac->entry[ac->avail++] = objp; +} + #ifndef CONFIG_NUMA #define drain_alien_cache(cachep, alien) do { } while (0) @@ -749,16 +759,6 @@ static void drain_alien_cache(struct kmem_cache *cachep, } } -/* &alien->lock must be held by alien callers. */ -static __always_inline void __free_one(struct array_cache *ac, void *objp) -{ - /* Avoid trivial double-free. */ - if (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) && - WARN_ON_ONCE(ac->avail > 0 && ac->entry[ac->avail - 1] == objp)) - return; - ac->entry[ac->avail++] = objp; -} - static int __cache_free_alien(struct kmem_cache *cachep, void *objp, int node, int page_node) {