Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4032095ybf; Tue, 3 Mar 2020 18:23:48 -0800 (PST) X-Google-Smtp-Source: ADFU+vt3WTsTeFmJtGFK9W5zFvbrggw2piPt4xhpzEPgybgTyQeSSYrveK8yKF63szMt8j/VY/jb X-Received: by 2002:a05:6830:2157:: with SMTP id r23mr699869otd.98.1583288628743; Tue, 03 Mar 2020 18:23:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583288628; cv=none; d=google.com; s=arc-20160816; b=TPZB1jzpYxEq0iHhxfodepuiRCZ48mGNV/WchXwKtpnyk+kAI35AQrLH01iYZWoIOn gRmVpA9eJeoXoqS6HYDwXQ8mhM7sG4MuYfPdTfFGlr2ti6cNNFXnpF2I3A0Oz0vbjvra X5JoodaqdQUTmhZfqeTcQyzhE+EFDZk3EbjZutx//8v3U2QY7P9/wtVsPPPREcQGitgP jMi7D4vtaR1xGgcR+TpyBFg0MbBsKGVZlPCuSYvRycTlmY1EAo4i3HraLr9TrvQOmycX S0fH4pHigy2BKXU33ol6Q/rFeax9p4C0deMD/S2S+w+Zj7AOBkjKQinv2FUytzESNszb xitg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=OslAV9mLJU87ShUgNDM/Y8Td4Fc/ZYoQgnZ+SA4jRP4=; b=tpiRRKoXxfdfThM6jUSOMKuIXmu6KWyz0pr+BHfGPHlmjC+fX5ASa0lA0SRIYHRMQi ejhU8/bPppkwEZdmoTepoCZYKDpD79OuvKcOt1d3yyuUyRaucK1FtXsLyisaBhiK3jA7 lDFCLQsIKqTesKhvCD8ShW5FIn0PTREXcvMrVe/oW9DGAvmyRZY8TBUFNHnt+kldZHDQ ONN8nBBLLlhDWF7ddkbgCmFPTUA02o8X3WQlcxRTC8/ko9kvNR1k4n75hZ6U08PABk0d 93zC6qfih2kaPKbH9BL/slfztvFEWxVPcq6H1b/LtuOIMCgbxz30Sl201b/8I3huRQuL pJJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HZHcs+kJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w202si300356oia.157.2020.03.03.18.23.36; Tue, 03 Mar 2020 18:23:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HZHcs+kJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387476AbgCDCWl (ORCPT + 99 others); Tue, 3 Mar 2020 21:22:41 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38073 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387400AbgCDCWl (ORCPT ); Tue, 3 Mar 2020 21:22:41 -0500 Received: by mail-pl1-f195.google.com with SMTP id p7so308176pli.5 for ; Tue, 03 Mar 2020 18:22:39 -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:references:mime-version :content-disposition:in-reply-to; bh=OslAV9mLJU87ShUgNDM/Y8Td4Fc/ZYoQgnZ+SA4jRP4=; b=HZHcs+kJbkyqAdCktVsPVxMpigjF33NHQ91BkSN+PulxJBMgYMzvMbm4KzGsjfhnEs 98hO8Cp/py0wqnLnm6Sd1ZMHD7UCzv20T/zBnr7LbgrRnf4/UFz70NpqHG5WGa5o12Pu GXT5j2FaD+x0WyG8OVtedJ++tVbwJJ2szUp0M= 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=OslAV9mLJU87ShUgNDM/Y8Td4Fc/ZYoQgnZ+SA4jRP4=; b=drJzucmjj2tNao8w38LixrT0axUD6MT/aGx9yxGvpQWeEC5ft6QEW0SrAgzKuPZE1o GgthstjiuBWmNlun4gXh8ZQUSif6DXvWpuMto24yN0dA7Fa2b1gl76PDg6i9hG1p8dmy BkimxEdRCoXL3XB01kWcAM5c84Bp1I+t3ueur0PQcKowGWbHpHRaYvQpOQFmWip38lLi tbvTMd7GqL5/rVXZUxK7q5HcKvsjDcTbwQIlv4zLe/5PUI7HHNS0sd/SUe/ZgcGWLbJA QpkmNjJ4WzL7negAE0pl3pdXk2U66mtzK8zNlZJOGtVbck9fXIseH1zkH5hrNsiIaQKH dkCQ== X-Gm-Message-State: ANhLgQ2YU8r8lA5JLwnBYtR494m0ct77zB+CD1/84nmrRsqceyeFhEGX 8wRmvifSJhqQ59a1ZGMzM8OKrg== X-Received: by 2002:a17:90a:9af:: with SMTP id 44mr633178pjo.160.1583288559031; Tue, 03 Mar 2020 18:22:39 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 15sm19917985pfp.125.2020.03.03.18.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 18:22:38 -0800 (PST) Date: Tue, 3 Mar 2020 18:22:37 -0800 From: Kees Cook To: David Rientjes Cc: Jann Horn , Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton , Linux-MM , kernel list , Matthew Garrett Subject: Re: SLUB: sysfs lets root force slab order below required minimum, causing memory corruption Message-ID: <202003031820.7A0C4FF302@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 05:26:14PM -0800, David Rientjes wrote: > On Wed, 4 Mar 2020, Jann Horn wrote: > > > Hi! > > > > FYI, I noticed that if you do something like the following as root, > > the system blows up pretty quickly with error messages about stuff > > like corrupt freelist pointers because SLUB actually allows root to > > force a page order that is smaller than what is required to store a > > single object: > > > > echo 0 > /sys/kernel/slab/task_struct/order > > > > The other SLUB debugging options, like red_zone, also look kind of > > suspicious with regards to races (either racing with other writes to > > the SLUB debugging options, or with object allocations). > > > > Thanks for the report, Jann. To address the most immediate issue, > allowing a smaller order than allowed, I think we'd need something like > this. > > I can propose it as a formal patch if nobody has any alternate > suggestions? > --- > mm/slub.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/slub.c b/mm/slub.c > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3598,7 +3598,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) > */ > size = ALIGN(size, s->align); > s->size = size; > - if (forced_order >= 0) > + if (forced_order >= slab_order(size, 1, MAX_ORDER, 1)) > order = forced_order; > else > order = calculate_order(size); Seems reasonable! For the race concerns, should this logic just make sure the resulting order can never shrink? Or does it need much stronger atomicity? -- Kees Cook