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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 5A8A9C433DF for ; Fri, 5 Jun 2020 21:06:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A0032074B for ; Fri, 5 Jun 2020 21:06:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AqB3Nh2m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A0032074B 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 B828C280002; Fri, 5 Jun 2020 17:06:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0AEC8E0006; Fri, 5 Jun 2020 17:06:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FA81280002; Fri, 5 Jun 2020 17:06:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 87CCF8E0006 for ; Fri, 5 Jun 2020 17:06:52 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4BA62180AD806 for ; Fri, 5 Jun 2020 21:06:52 +0000 (UTC) X-FDA: 76896392664.10.sort22_21093bd26da3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 1F9E7168816 for ; Fri, 5 Jun 2020 21:06:52 +0000 (UTC) X-HE-Tag: sort22_21093bd26da3 X-Filterd-Recvd-Size: 4438 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Jun 2020 21:06:51 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id jz3so3167224pjb.0 for ; Fri, 05 Jun 2020 14:06:51 -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=KxCH5EFraXoQSEVf3oiNZdVbXVBoYbhiatH91ouNAhE=; b=AqB3Nh2mTRZNCXSeorHCNmPub68+StVvbdM9uqA0v/3Yb3F91Cs5xewCqGEpfFrNHK FO1K+k2kdb9Skdy/iEqfAG/yRuLdkl2FmeJHFJK2Yoc+cTqTUIvq6DuSuJ55FJffurvr sYO6fsoN3uCqh+5ieK6JgXecwbgdXOM7W8u9c= 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=KxCH5EFraXoQSEVf3oiNZdVbXVBoYbhiatH91ouNAhE=; b=WgTktqomh7NOAspqGEvNtWriasInbPCIR81dStp+p2B101sR1jFMX6ALOzyOTgyuFF hIIQeHXiyf57VsJ7/DQr9DDUGMz97uQbBg3jfOKek7nax8XW/Ck8L/M3T5h/Pcd2psD0 YeCe+EQx2YqfNXSrNTIm0OZkACfSgovL+hs+Avdmh9fjtmwSVFDyGpNrrsyH3WMTqOHe OFCXa06r2GZSaVbYpYEv9/F4L21M0LYCq0Cwkoajch2E9o/zfLsvRnejIk3Ore+8W7V4 isaFqxYomypH6mqsicDIeoWavu5UTx51x1M2rHQjI6c+3dcsaPcFoXE+dxS/7bhtdyBz yeyQ== X-Gm-Message-State: AOAM531MhImv3PqRyPofEaxpdntGgEcScwMfocSQHoKhw6fxVJPmprmT hD95osIYRpTKwnyRLnAoW8Ks4A== X-Google-Smtp-Source: ABdhPJwRIjKh0eeXvoAeIZcWHp5tbfvmDAMH4VkEyiDjLHJF5f6StU5vQ6ved+Dmiup8SU8qxDzpPw== X-Received: by 2002:a17:90a:ae11:: with SMTP id t17mr5275490pjq.157.1591391210874; Fri, 05 Jun 2020 14:06:50 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y9sm9183236pjy.56.2020.06.05.14.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 14:06:50 -0700 (PDT) Date: Fri, 5 Jun 2020 14:06:49 -0700 From: Kees Cook To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vinmenon@codeaurora.org, Matthew Garrett , Jann Horn , Vijayanand Jitta Subject: Re: [RFC PATCH 3/5] mm, slub: remove runtime allocation order changes Message-ID: <202006051406.A7AF17B6@keescook> References: <20200602141519.7099-1-vbabka@suse.cz> <20200602141519.7099-4-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200602141519.7099-4-vbabka@suse.cz> X-Rspamd-Queue-Id: 1F9E7168816 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: On Tue, Jun 02, 2020 at 04:15:17PM +0200, Vlastimil Babka wrote: > SLUB allows runtime changing of page allocation order by writing into the > /sys/kernel/slab//order file. Jann has reported [1] that this interface > allows the order to be set too small, leading to crashes. > > While it's possible to fix the immediate issue, closer inspection reveals > potential races. Storing the new order calls calculate_sizes() which > non-atomically updates a lot of kmem_cache fields while the cache is still in > use. Unexpected behavior might occur even if the fields are set to the same > value as they were. > > This could be fixed by splitting out the part of calculate_sizes() that depends > on forced_order, so that we only update kmem_cache.oo field. This could still > race with init_cache_random_seq(), shuffle_freelist(), allocate_slab(). Perhaps > it's possible to audit and e.g. add some READ_ONCE/WRITE_ONCE accesses, it > might be easier just to remove the runtime order changes, which is what this > patch does. If there are valid usecases for per-cache order setting, we could > e.g. extend the boot parameters to do that. > > [1] https://lore.kernel.org/r/CAG48ez31PP--h6_FzVyfJ4H86QYczAFPdxtJHUEEan+7VJETAQ@mail.gmail.com > > Reported-by: Jann Horn > Signed-off-by: Vlastimil Babka Reviewed-by: Kees Cook -- Kees Cook