From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 56D8AC47082 for ; Tue, 8 Jun 2021 18:26:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E4D0961352 for ; Tue, 8 Jun 2021 18:26:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4D0961352 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 6A7366B006C; Tue, 8 Jun 2021 14:26:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 657076B006E; Tue, 8 Jun 2021 14:26:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D13C6B0070; Tue, 8 Jun 2021 14:26:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id 17EFE6B006C for ; Tue, 8 Jun 2021 14:26:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A99678249980 for ; Tue, 8 Jun 2021 18:26:53 +0000 (UTC) X-FDA: 78231387906.07.032C474 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf16.hostedemail.com (Postfix) with ESMTP id 6345B801935A for ; Tue, 8 Jun 2021 18:26:50 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id h12so13533751pfe.2 for ; Tue, 08 Jun 2021 11:26:53 -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:references:mime-version :content-disposition:in-reply-to; bh=Ndln2EuNlB+CP5mLiP3hdXT+nVwUYUAuTcfdG/dVXpU=; b=JL0mYsIjZFqW0K0buK/ZoqO8gB6RoLQ1xk0cIT0uvFwpxp0HDL0jLR647mH4HWhXWK 7yGLyni/v6LOZwD66AOwZsqEf1AqrwLX+thpddZOS198keGEBHxxvv3ftPkMCrf+gHO+ v3Hid4jVRPXCkteont5eNR9OzdANVZqDTlqHU= 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:references :mime-version:content-disposition:in-reply-to; bh=Ndln2EuNlB+CP5mLiP3hdXT+nVwUYUAuTcfdG/dVXpU=; b=J78/ObslGm2JhMKrBVsvEkyznmLR1boQPpPAVjFToruD2dognlyLLDJwNmlvU2oKvN VHsFExH6A33o9K1V4IPVYz59u4y1h3/vx/pixRPGMnR6m2kux+yMdv0pwDVRUmWr5Fig zJ3DG8UiKsYwD0rbVTqpsjJsIMqOE6NVHXy4tTZ+rxnb1asHzBVj0pP/dBwl1t7j74wk mJvvD0xa82WNUzy3Xmyqw5XvS9TIp/ZldZe1SGQpevEEQc5+W+c6/Ql7dFCJKgzN4uQf x3DB6P6FBSduEh6+lmUrEyik/kd2tA/bDXyv/jzn3uFb6hKFmrZFut/seEyA90AmT/7k L3xg== X-Gm-Message-State: AOAM531eeXqu4RzK+DmjBa1FnmkIkAW3i513lbOS2CkhOtvcWZ3ZNAGL C19ttZZPQvYZVrtP7llwgoqQTQ== X-Google-Smtp-Source: ABdhPJwTV2ZRR+J0IP/czfDPzPV669yVdHAMzM/WGvcXMbGOKH9gqjfxZrHbaKtAgI6WYhPrnRrgBA== X-Received: by 2002:a63:ff22:: with SMTP id k34mr23730897pgi.336.1623176812105; Tue, 08 Jun 2021 11:26:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y5sm11635762pfo.25.2021.06.08.11.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 11:26:51 -0700 (PDT) Date: Tue, 8 Jun 2021 11:26:50 -0700 From: Kees Cook To: "Lin, Zhenpeng" Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] slub: choose the right freelist pointer location when creating small caches Message-ID: <202106081125.E2DA4DE8@keescook> References: <6746FEEA-FD69-4792-8DDA-C78F5FE7DA02@psu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6746FEEA-FD69-4792-8DDA-C78F5FE7DA02@psu.edu> Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JL0mYsIj; spf=pass (imf16.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.175 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6345B801935A X-Stat-Signature: 6amm94uttm44h8u1pa17ppen4ybruy44 X-HE-Tag: 1623176810-182929 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: On Sat, Jun 05, 2021 at 01:58:13AM +0000, Lin, Zhenpeng wrote: > When enabling CONFIG_SLUB_DEBUG and booting with "slub_debug=Z", the > kernel crashes at creating caches if the object size is smaller > than 2*sizeof(void*). The problem is due to the wrong calculation > of freepointer_area. The freelist pointer can be stored in the > middle of object only if the object size is not smaller than > 2*sizeof(void*). Otherwise, the freelist pointer will be corrupted by > SLUB_RED_ZONE. > > Fixes: 3202fa62fb43 ("slub: relocate freelist pointer to middle of object") > Fixes: 89b83f282d8b ("slub: avoid redzone when choosing freepointer location") > Signed-off-by: Zhenpeng Lin > --- > mm/slub.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 3f96e099817a..cb23233ee683 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3704,7 +3704,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) > * can't use that portion for writing the freepointer, so > * s->offset must be limited within this for the general case. > */ > - freepointer_area = size; > + freepointer_area = s->object_size; > > #ifdef CONFIG_SLUB_DEBUG > /* > @@ -3751,7 +3751,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) > */ > s->offset = size; > size += sizeof(void *); > - } else if (freepointer_area > sizeof(void *)) { > + } else if (freepointer_area >= 2 * sizeof(void *)) { > /* > * Store freelist pointer near middle of object to keep > * it away from the edges of the object to avoid small > -- > 2.17.1 NAK, I'd prefer this get cleaned up more completely, especially since there are no objects of that size in the kernel currently: https://lore.kernel.org/lkml/20201015033712.1491731-1-keescook@chromium.org/ -- Kees Cook