Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4885118ybf; Wed, 4 Mar 2020 12:41:24 -0800 (PST) X-Google-Smtp-Source: ADFU+vu02Z+Wd3df0GOW2I4vbwJW9iKGlRT+AU6yYAXYN6wTQZNlClAtCF8kjjfX2rk/uQ6X99nk X-Received: by 2002:a05:6830:1e58:: with SMTP id e24mr3928208otj.267.1583354484241; Wed, 04 Mar 2020 12:41:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583354484; cv=none; d=google.com; s=arc-20160816; b=F9Orvl09pyYUq0K2djHS18jsVwDMGGfkvjCCnL9aH52v5Dcr6sDp5dpY3rfsgDibNK pvME5iWWonun69YwA/Ohfy4cswDm84ozrqP6VQjZgCPa4aumcUf5MbLogqXqBqoJphTD nivI3ETcZIqqS6m66sra448KCa5as5KBB6+scrxIHMgV5CtUtOX+ckgn+EcPhazRL/Dj IFEKuXqMgKgOav4CJRj8EHmI0Vy5GkfGzR9WMZcAg4oVjwp2cfkJqUv/hBiGMkldjgtu q5XZiU7OKi5Zsjc+SHxZ+wJlI2QxFmXC6PWpk+zwzP6HzkLdVfpAkW7EL6FFiW9g9/e2 uCxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=wNgtMzd+gzlBfLnh+JlMLwQ7VKkmR77B7QNl9jJRgI8=; b=LM3+Vm0J1O35epeCVo4VvAuYXdJcFtpcYG7T3H+Gx054bMap8tRnp5vLh4aks9n/Fj Ir3+jPOigjMbAsPS+JXG4dtmqGnT+pgF0h18j7YBQd9tMPcB7HJTLrOC+/FPz1ldMzso ILwmXOELMjRslVhz4ZSyiom9TtEAxxehIK1KbmkczgaHkxCtqQoWCG7cejNFUTmG1XpJ aIqaL8GrlxhM640SDRx11R2ORBuju486QnsCNgHCjEcaNebDCtN4sCZ6mcCST8p6Sl3X ERKvn91yHj86AU1H1rq2thdOXx1Cwpi/AttFGjJC7zfuyVx7HInOqbjXN+nG+8Z1IKpJ iXXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JWmmsvlv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p16si2160424ota.41.2020.03.04.12.41.11; Wed, 04 Mar 2020 12:41:24 -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=@google.com header.s=20161025 header.b=JWmmsvlv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728642AbgCDUj4 (ORCPT + 99 others); Wed, 4 Mar 2020 15:39:56 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46313 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbgCDUjz (ORCPT ); Wed, 4 Mar 2020 15:39:55 -0500 Received: by mail-pg1-f193.google.com with SMTP id y30so1528745pga.13 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=Q+NvhXFfgJtjz03wKZixi+UxjEOtWhnOYa7zqgIzxGwtccw4koJSPixFPz2UXYYeIr jbvYYUs5pYM4Zev/ZA3iLub11SIi1Qg5cyH5FUSgkGJtJhSfWfBxpg2qN8bO10OLYji2 c0C41P4HbcpH8p2+S3nXvisPfXH2D66Vmmn/wZMoGxuKrh1allP+2zW68927O8/mj8Jp T99FUyyPydr2c4fD5lDsbGFd3pxxIrq+15dsJMxZxClzVcXd5aNLMFwuUwGlBRfyo8ma iYSUOiIRIGJU9wqQpOI4LQlES9IFV+LN46pJlU5qQpsa69aXiJn+AUjQyCrKoC/29hpz dC6g== X-Gm-Message-State: ANhLgQ2CwG+6Xp2RIV2pXm0Z1aTkPeGXqs9chrIPgTDyC3asXgk6JinF +KAo/wY1oE6G93gRb6o85FNB4A== 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.