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=-9.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL 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 854DFC3F2D7 for ; Wed, 4 Mar 2020 20:39:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 40FD821775 for ; Wed, 4 Mar 2020 20:39:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JWmmsvlv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40FD821775 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B5FEE6B0003; Wed, 4 Mar 2020 15:39:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC35B6B0005; Wed, 4 Mar 2020 15:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B22E6B0007; Wed, 4 Mar 2020 15:39:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 7F89C6B0003 for ; Wed, 4 Mar 2020 15:39:56 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 240DA181AC9CC for ; Wed, 4 Mar 2020 20:39:56 +0000 (UTC) X-FDA: 76558846392.01.size45_3997bfeb8a101 X-HE-Tag: size45_3997bfeb8a101 X-Filterd-Recvd-Size: 5459 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Mar 2020 20:39:55 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id n7so1563208pfn.0 for ; Wed, 04 Mar 2020 12:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=wNgtMzd+gzlBfLnh+JlMLwQ7VKkmR77B7QNl9jJRgI8=; b=JWmmsvlvaY1+Xsw8BMsiCecCaQ4C6vdTOgVcJbr16hxEsxKVvuVwmJF73Dg4cwtDrf V9iU+A0JOxLHP5L9HO6eHO8pu2LTPKSJScrKnX81yOqMuW1niTm8mGzyyZmEYnKqyYaL r//ADjUDdTtGj0GzxlvtVuacqu6ZeK4qcvuEiMiheL4nkpHyJ8uGxznOo7ZvaMtXvPsU 4V7JGtKe5Gcl4Ow+qJpPF5ZMh3pYXFhXEnO8nwIyshZXY7rCzvQHSECjnI05bhci0Egz M4Daq/CBEiVT/mLECdhfvtGdfVNXTX7CqqMgweWmbvsI7tn2aHvYhjIQcf9YMRPP1JSD mfaA== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=wNgtMzd+gzlBfLnh+JlMLwQ7VKkmR77B7QNl9jJRgI8=; b=ktF1Jb9oLZpkNOFJTnrGspf4z8wga7nezQpGjjkX0FcGdrLQRXsVJIovSn8p0VfeaT cBfCvq+Ql+hs7r/nOlcOVs+GnVj7OACq0qkvSyJArIU/ZaNte5TRDmHboilTlFyK8HWo 7mUe3APXLabq9OPpJ2i3+ewocxY/ORpzeXCNnRWXLP4XVB5g4Q/U6SAwbAD2VEmUPFZW OjKPOcBwvCjGEasJAf2Mglin36qxCQTVIBBWb+wEMwtuNbZfEyYDx6YabYhXHRl7JsaW 8wBO64KeBajjc64IEt3Vn2IzyCOr/RSwXSPXoASZIoeCh8bHcEn1DAf7o8weeIGLP4wk zcNw== X-Gm-Message-State: ANhLgQ3eJX+jtcmkTlAZDFU8iVjJU1FLU7sm9jwaNQpAAIiOmZWFpkia PpDZRvBPY0HLvzXTYWz+ad4BMA== X-Google-Smtp-Source: ADFU+vtdNfS/21YQBCu3RzuP8szM7y2EJjTVf2/6DbhY7+hK9OOE3GcBbqDmMsZNViPQRtxGytPoTA== X-Received: by 2002:a63:565e:: with SMTP id g30mr4080275pgm.206.1583354394350; Wed, 04 Mar 2020 12:39:54 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id g16sm29970389pgb.54.2020.03.04.12.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 12:39:53 -0800 (PST) Date: Wed, 4 Mar 2020 12:39:52 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Vlastimil Babka cc: Kees Cook , Jann Horn , Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton , Linux-MM , kernel list , Matthew Garrett , Vijayanand Jitta Subject: Re: SLUB: sysfs lets root force slab order below required minimum, causing memory corruption In-Reply-To: Message-ID: References: <202003031820.7A0C4FF302@keescook> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 Wed, 4 Mar 2020, Vlastimil Babka wrote: > > 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? > > If order grows, I think we also need to recalculate the random sequence for > freelist randomization [1]. I expect that would be rather problematic with > parallel allocations/freeing going on. > > As was also noted, the any_slab_objects(s) checks are racy - might return false > and immediately some other CPU can allocate some. > > I wonder if this race window could be fixed at all without introducing extra > locking in the fast path? Which means it's probably not worth the trouble of > having these runtime knobs. How about making the files read-only (if not remove > completely). Vijayanand described a use case in [2], shouldn't it be possible to > implement that scenario (all caches have debugging enabled except zram cache) > with kernel parameters only? > I'm not sure how dependent the CONFIG_SLUB_DEBUG users are on being able to modify these are runtime (they've been around for 12+ years) but I agree that it seems particularly dangerous. I think they can be fixed by freezing allocations and frees for the particular kmem_cache on all cpus which would add the additional conditional in the fastpath and that's going to be required in the very small minority of cases where an admin actually wants to change these. The slub_debug kernel command line options are already pretty comprehensive as described by Documentation/vm/slub.rst. I *think* these tunables were primarily introduced for kernel debugging and not general purpose, perhaps with the exception of "order". So I think we may be able to fix "order" with a combination of my patch as well as a fix to the freelist randomization and that the others should likely be made read only.