From patchwork Mon Aug 24 13:06:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 11733191 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 68FFD1510 for ; Mon, 24 Aug 2020 13:08:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F62620838 for ; Mon, 24 Aug 2020 13:08:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F62620838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=de.adit-jv.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4B6EC8D001F; Mon, 24 Aug 2020 09:08:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 466AC8D0007; Mon, 24 Aug 2020 09:08:40 -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 37CD58D001F; Mon, 24 Aug 2020 09:08:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 228EF8D0007 for ; Mon, 24 Aug 2020 09:08:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D2809180AD81D for ; Mon, 24 Aug 2020 13:08:39 +0000 (UTC) X-FDA: 77185491558.20.grass84_2a0ba8327053 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 65FBF180C1465 for ; Mon, 24 Aug 2020 13:07:17 +0000 (UTC) X-Spam-Summary: 80,0,0,5d5d26014662ea63,d41d8cd98f00b204,erosca@de.adit-jv.com,,RULES_HIT:41:355:379:541:582:800:960:965:966:967:973:988:989:1152:1260:1261:1277:1311:1313:1314:1345:1431:1437:1515:1516:1518:1534:1542:1711:1730:1747:1777:1792:2196:2199:2393:2525:2553:2559:2565:2570:2682:2685:2703:2859:2895:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3353:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4390:4395:4425:4605:5007:6117:6119:6261:7875:7903:7974:9025:10004:10400:11658:13161:13229,0,RBL:93.241.18.167:@de.adit-jv.com:.lbl8.mailshell.net-62.14.6.180 64.201.201.201;04yrx1uq6qiwfdgj5xz1fe35eqz65opewrkt7hyq3jf9sewdqscc5c616wkq3pa.6nznc3gzx991rj6wdpnu5cdurim7r53ee4qrsetk5dugo7npxaii474gs4hdd5j.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: grass84_2a0ba8327053 X-Filterd-Recvd-Size: 4585 Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Aug 2020 13:07:16 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id A30383C0579; Mon, 24 Aug 2020 15:07:13 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rS9E865DscdH; Mon, 24 Aug 2020 15:07:08 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 920423C0016; Mon, 24 Aug 2020 15:07:08 +0200 (CEST) Received: from lxhi-065.adit-jv.com (10.72.94.3) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Mon, 24 Aug 2020 15:07:08 +0200 From: Eugeniu Rosca To: Andrew Morton , Dongli Zhang CC: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , , , , Eugeniu Rosca , Eugeniu Rosca Subject: [PATCH v2] mm: slub: fix conversion of freelist_corrupted() Date: Mon, 24 Aug 2020 15:06:43 +0200 Message-ID: <20200824130643.10291-1-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Originating-IP: [10.72.94.3] X-Rspamd-Queue-Id: 65FBF180C1465 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Commit 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()") suffered an update when picked up from LKML [1]. Specifically, relocating 'freelist = NULL' into 'freelist_corrupted()' created a no-op statement. Fix it by sticking to the behavior intended in the original patch [1]. In addition, make freelist_corrupted() immune to passing NULL instead of &freelist. The issue has been spotted via static analysis and code review. [1] https://lore.kernel.org/linux-mm/20200331031450.12182-1-dongli.zhang@oracle.com/ Fixes: 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()") Cc: Andrew Morton Cc: Dongli Zhang Cc: Signed-off-by: Eugeniu Rosca --- v2: - Address the review finding from Dongli Zhang in: https://lore.kernel.org/linux-mm/f93a9f06-8608-6f28-27c0-b17f86dca55b@oracle.com/ -------8<------- This is good to me. However, this would confuse people when CONFIG_SLUB_DEBUG is not defined. While reading the source code, people may be curious why to reset freelist when CONFIG_SLUB_DEBUG is even not defined. -------8<------- v1: - https://lore.kernel.org/linux-mm/20200811124656.10308-1-erosca@de.adit-jv.com/ mm/slub.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 68c02b2eecd9..d4177aecedf6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -672,12 +672,12 @@ static void slab_fix(struct kmem_cache *s, char *fmt, ...) } static bool freelist_corrupted(struct kmem_cache *s, struct page *page, - void *freelist, void *nextfree) + void **freelist, void *nextfree) { if ((s->flags & SLAB_CONSISTENCY_CHECKS) && - !check_valid_pointer(s, page, nextfree)) { - object_err(s, page, freelist, "Freechain corrupt"); - freelist = NULL; + !check_valid_pointer(s, page, nextfree) && freelist) { + object_err(s, page, *freelist, "Freechain corrupt"); + *freelist = NULL; slab_fix(s, "Isolate corrupted freechain"); return true; } @@ -1494,7 +1494,7 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects) {} static bool freelist_corrupted(struct kmem_cache *s, struct page *page, - void *freelist, void *nextfree) + void **freelist, void *nextfree) { return false; } @@ -2184,7 +2184,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, * 'freelist' is already corrupted. So isolate all objects * starting at 'freelist'. */ - if (freelist_corrupted(s, page, freelist, nextfree)) + if (freelist_corrupted(s, page, &freelist, nextfree)) break; do {