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,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B3677C3F2C6 for ; Wed, 4 Mar 2020 02:22:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4C6D320842 for ; Wed, 4 Mar 2020 02:22:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HZHcs+kJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C6D320842 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 018766B0003; Tue, 3 Mar 2020 21:22:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0B956B0005; Tue, 3 Mar 2020 21:22:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFA8A6B0006; Tue, 3 Mar 2020 21:22:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id C7BC26B0003 for ; Tue, 3 Mar 2020 21:22:40 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ACF9682499B9 for ; Wed, 4 Mar 2020 02:22:40 +0000 (UTC) X-FDA: 76556081280.22.start64_518a75415fd02 X-HE-Tag: start64_518a75415fd02 X-Filterd-Recvd-Size: 4672 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Mar 2020 02:22:40 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id dw13so198279pjb.4 for ; Tue, 03 Mar 2020 18:22:40 -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=W0qMEZChsWuVSHMROMIjMI7IMxZ+zSkpbGWVbgFhK4pu0iEO2e74MF58eDpwOXmd6M CChgl0+pdu3wnfECmCqwbbCc1U72zzz2uhxdetc4BUu9TQDNkM+ZhDr311BP0H4veSFm u1TKI6QSY2qvtX/suZoFBeh/IfMVtgopOKfOhrwhkDH+6VkB+TIihRpS2oSlm9NYMu5A +aOxxBeoQ0J9dZtfQJtGtkIbDCuqIotIpm5MI6rQQ8rgTBflPKM8trpNCvOBdjoU3sBI xkH5F5E5PD5vLJ/Yl0jV7sDHX0yzd3X0VzJ7x1QLBLBZKfSkTTkQq4j8GfCMZfBrbZH9 Z3Gg== X-Gm-Message-State: ANhLgQ1o79QSwf4C+wpPy7c2NjZK6at6HYK5Acjs/FvYNYlS6XUXDTyD kMdq4ViAap+czxLtdwHT09LOLw== X-Google-Smtp-Source: ADFU+vv3JgHanygZXMBTQGHaaGvwMvnLimCLJ+XENS0VT2G8oSXcmGbWrdbcaCjBKhPBhC1A1tbsJQ== 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: 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, 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