From patchwork Mon Feb 12 21:38:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67456C4829D for ; Mon, 12 Feb 2024 21:39:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15CFA6B0087; Mon, 12 Feb 2024 16:39:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10BC56B0088; Mon, 12 Feb 2024 16:39:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E799F6B0089; Mon, 12 Feb 2024 16:39:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D18A36B0087 for ; Mon, 12 Feb 2024 16:39:52 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9EFB5120A6C for ; Mon, 12 Feb 2024 21:39:52 +0000 (UTC) X-FDA: 81784469424.15.8D21F52 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf13.hostedemail.com (Postfix) with ESMTP id E1D3A2000F for ; Mon, 12 Feb 2024 21:39:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=s+4UimYS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3JZDKZQYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3JZDKZQYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707773990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MHmYMVX3pDUmg31UH8awuyUsQFI7ijlFGj9IhCGVNQw=; b=35BLVeXG/yijidyQ3+Vf4lY1QRZGgZQYzU/WgtQNXQiMl6LII+D/BlIokcpbhvCrkYKXbC plqFgn5O+wOxqwj6XttzAQ7EpdFrtJtvzgEqJAybxIw4TDwVR5WQoB5QO/rQPSpXreJSKa H9ugZqfedV2xBLwnd94lLsh33SQyi98= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=s+4UimYS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3JZDKZQYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3JZDKZQYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707773990; a=rsa-sha256; cv=none; b=sWwebsIIq04APVIadd68flFrzzi22oKBb4yoBy7Fzz09IfIq8lRHg7b+jiDzmjsO1vKO45 +hDA/e1t3CkcjbByV4vNRfi3HSdZ8gQ0fek6sYC0qWpIsfMemVc78icDulRdZq2CVNkQrt 30irKnqJaX3PPhJQq6+QhLKu258HRe8= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6077e9dd249so4426887b3.3 for ; Mon, 12 Feb 2024 13:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707773990; x=1708378790; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MHmYMVX3pDUmg31UH8awuyUsQFI7ijlFGj9IhCGVNQw=; b=s+4UimYSWTxNf/lD8dQetJQREcmpIU/EQj7c0A5yJAmTWaNL6j3NiTQVCv5you+GTb 8HNLRW8Bai91i2dyUIQJZGEDIqQm2yAEMM4JJ/tRz8sx8XyCxNl/+ixxTrxRD1YxtP7O cedKJ5FHP8TvdjI+mWzIay9UU3pLnkQpRBNo4qPKKkQWumXDWD+CKKo0TjOosW3c3TgT pii3EJCBv3xQM+gQ07oNQma5hrBIt+TwYm3pY3HB/q8GadQjny3olyajQd4fiBKNqW31 Roylr6j9KPLUhU9d+hDGsni7PLOlkBOBKj0TfPFY+kn+al2jVcrcr6Z/zW7GU61vclrd esAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707773990; x=1708378790; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MHmYMVX3pDUmg31UH8awuyUsQFI7ijlFGj9IhCGVNQw=; b=aa0zJTSRmvKNDspTLR7FzsbHKF6K4U7OWsentBHOvbKrK/G4ZhDY+nqgiBBxMqyXmG +N3znLYQfAEZI74tjDYWCRsgpZwoGnJ+MgnOdA/TrbWP2W/zZu+Aof8mDQxlFd5fMapD Fh5SH861RzZ+q7xNj6Ofx55oRvynkhAkhdJa93gQ6VvM/S20MvR07k37WhCqZBNjGwgn Ztsxt2gWAc4PClM5bj4XurLZr9wLKf1szzSgAQe+I/LSTa3lFaSzQ7snszDkcbw/9l3n 8mnZWhhvgRH/WckPQqwJEzx19+REOkrKR8CCYjPMvSIidMZ0MCmdyxFiN6AJRli0ty4W bd7A== X-Forwarded-Encrypted: i=1; AJvYcCVoibF+l0xFYYeCAymQzMz/yNgMkA+VifBBj65hoKxZkKjwJdlsQ4n6I7Z+6wle3FoYj5138oZB3gRYT6KQPdgifX4= X-Gm-Message-State: AOJu0YznyGLUP1WJqpO94EO2VeWxseF6cjVOmFNXqK1AWcU7yvIHjG1p 50pA0lLGyKqLodciltGxIa/f3WK9gsapKUsvpDgvC7YSEhQxYQoCf2xz4cxPsY0fQb4oVBQSlGY vvQ== X-Google-Smtp-Source: AGHT+IFDzjF2cGPjf9byIT/iUDxPrFM8RUYETPrPWdKRGwVNA8HPcuChMwLVorzqu+gtL/yYLkx2m1ZVYB4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a05:690c:fd0:b0:602:cd1a:6708 with SMTP id dg16-20020a05690c0fd000b00602cd1a6708mr1449899ywb.0.1707773989875; Mon, 12 Feb 2024 13:39:49 -0800 (PST) Date: Mon, 12 Feb 2024 13:38:54 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-9-surenb@google.com> Subject: [PATCH v3 08/35] mm: prevent slabobj_ext allocations for slabobj_ext and kmem_cache objects From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Rspamd-Queue-Id: E1D3A2000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ta5obciej496fz7xnfswspimc9zub779 X-HE-Tag: 1707773990-249842 X-HE-Meta: U2FsdGVkX1++YAia//sKw+gwL3rV4DqvnJf3sTepda3B8Q36XbySQiRk4mtJ3pxDJ4gxzZuuwe7wTSji9GimfP2txzHPDntsEsKADB/Cgbo5pSFyxyTEaqcpHAYBYyRAzTO81QguBCmwgWYvBJZOBMLqCzzEmrzi1wwembBPuZoAyizS8JBUyFdC60GSeBvSR7XYyaWLX5c2pqZC57rtpmX1BHBRUOGwhuHv+uksAlAYAaYppViQglazgMmajwnkqaM1gFwmUkwboUt6BGjWpY86qTMzliARS4YSYn3D81e6BMKD9oSB3GraEiroyLBmd8J8mnuoIjPaWkzBhRkPN5sNNyWjwOzkdA/pH5Mr47PFyZKXocAfjxsUykWLRYk9rlpSaZdH8rZdLJLiieuqWtUYRgS4HQNqRExFdhMf2th4kwzo1vTAqtH4LF7LS7OovXtvR/9U4dN59JVvNVJ59g2/GL9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ddP13MCzK8vmQsoI8w5YlP2bzgKmkZUZk60NBbBJQ27jheNaykEl40N8t6/YPMV1iluRmR54oQYtG78IS5Gk2NA+NvLSuDRg4XRHXsWu63J3sVnzVu5oNE4yD4ZHXSqxzUVIhzw5Q5ZDs6GF4IkZT6uxGQKqK6lCE9JDbTF/JM 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: List-Subscribe: List-Unsubscribe: Use __GFP_NO_OBJ_EXT to prevent recursions when allocating slabobj_ext objects. Also prevent slabobj_ext allocations for kmem_cache objects. Signed-off-by: Suren Baghdasaryan Reviewed-by: Kees Cook --- mm/slab.h | 6 ++++++ mm/slab_common.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/mm/slab.h b/mm/slab.h index 436a126486b5..f4ff635091e4 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -589,6 +589,12 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) if (!need_slab_obj_ext()) return NULL; + if (s->flags & SLAB_NO_OBJ_EXT) + return NULL; + + if (flags & __GFP_NO_OBJ_EXT) + return NULL; + slab = virt_to_slab(p); if (!slab_obj_exts(slab) && WARN(alloc_slab_obj_exts(slab, s, flags, false), diff --git a/mm/slab_common.c b/mm/slab_common.c index 6bfa1810da5e..83fec2dd2e2d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -218,6 +218,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, void *vec; gfp &= ~OBJCGS_CLEAR_MASK; + /* Prevent recursive extension vector allocation */ + gfp |= __GFP_NO_OBJ_EXT; vec = kcalloc_node(objects, sizeof(struct slabobj_ext), gfp, slab_nid(slab)); if (!vec)