From patchwork Fri Feb 2 01:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13541977 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 9CB43C48286 for ; Fri, 2 Feb 2024 01:12:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3011C6B0072; Thu, 1 Feb 2024 20:12:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B15C6B0074; Thu, 1 Feb 2024 20:12:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 179536B007E; Thu, 1 Feb 2024 20:12:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 05D6A6B0072 for ; Thu, 1 Feb 2024 20:12:58 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DAE7EA0458 for ; Fri, 2 Feb 2024 01:12:57 +0000 (UTC) X-FDA: 81745089594.06.BC7F853 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf17.hostedemail.com (Postfix) with ESMTP id 20E3E40009 for ; Fri, 2 Feb 2024 01:12:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AA8CSdBg; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of dianders@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=dianders@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706836376; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Ivmfb83FwDkP3x6pfBlSqzRjLeN2tS1ZFLqnXqOH+KQ=; b=LjVOmBzQPSrwErO4hcdo/xbAKYx/lkYrvbCRJLpmuBouWpARI8G5wi5+sSjn2SN89wgpQc lt6Dk2LwxFuIgSLvHrdnPajHyCJ/jkisEQEPd6R0dVMuSfb6bezoU3yyRZ8PTdKD0kHo5d gmq8DARjQu+RpJbvXmUobuCNwl7klnk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AA8CSdBg; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of dianders@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=dianders@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706836376; a=rsa-sha256; cv=none; b=sNZpLZIsyn6qOlDCI3WAPoyIt1U1Bip/xjqfXkEtaf9NNtIuvSHCpwcWOfXA/9IXnLMXs5 f10aqq+oiQ2bF7mQT0Y2sueixhK5RWFCcGbn1Cr0Mi7P/7zSoxKnFKEUmPFybcUtCDb/mx h/pHmcmGygsuHNU2cfZTDZpWHpUYi6E= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6de28744a46so1206089b3a.3 for ; Thu, 01 Feb 2024 17:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706836375; x=1707441175; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ivmfb83FwDkP3x6pfBlSqzRjLeN2tS1ZFLqnXqOH+KQ=; b=AA8CSdBgscXmVQPs2MgW8rsm2FvAD46ZQcFkiOebn/v8aw/zPwxSiy627kUvNIiHIO XjdXsWqqNcsoYarw5+/s+pqKBxSo0SkdVs6uEsv73QpK1kZzhWa3Aptc68waVQAP38/D QwDm2ltnt5C1kfQC1+BgwtWamrpzHcym9EaJg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706836375; x=1707441175; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ivmfb83FwDkP3x6pfBlSqzRjLeN2tS1ZFLqnXqOH+KQ=; b=AWwyJZAbbs8oCeJdHUMP8Y8WIebHkAwZg+o1gyHoYs202hoPx8zC++BJhtReoc/r+v FLmbweuvsyicWcxQbKGOAuI/tEtadaZnQnZvpmAgXvITglPNqA1dQho+XPnxYe5N/Kvx 9l1pNdo9f9xLm1+k+ltOHSSP6TmYz5ofF//X9t7azW/uKYCBenv1CnYtCp8j7vD7Aa4m Nkyqa7yWYPhQ8tVgnrWrzRWDbIoz5exuF0XvPYmoSjTDbV/2MoNGHi0Z9m/XUwP6IL6O qzNgb9diY4sYxJc10DFqW+aXBwc+NZidifb9e9L+tIAypb6o1EO6bwzAtkvhgZ5iaSMN 1Beg== X-Gm-Message-State: AOJu0YxYBKJBYWY73ARL5wLBCIrkmi+82fZ+7RiAU9EorJsAtM4vhRV9 YXzqSJMN/YLYffm7cx1KayzOPniOX60OduWC5uN6OF5GO/31wiyJ4jW1bo+ETw== X-Google-Smtp-Source: AGHT+IFDLmhjSiFVUREChNi1Tz0JkUPOtT5xeLTdp3wsTuUWxF0qy+TElN2h3bus8LcjLTvkFWgsLQ== X-Received: by 2002:a05:6a20:1e4a:b0:19e:34e4:818e with SMTP id cy10-20020a056a201e4a00b0019e34e4818emr5927684pzb.8.1706836374922; Thu, 01 Feb 2024 17:12:54 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCX9Lpj6ULXgFZCsNzmvUHNd4fR20Uvm9EzQKaw5VFE+b9uGRRAZZuOix2g7mfo4/n8QpkXkGuL1XMuZdly9WCJXCWwjPKeEFq/8SurjdII7TyEl8ua0KJ7y0AQqocJE06RcJsDLN0DF1pMlTPAAKalV3CU0zxysbTjG9k9PtzkoTmv0VvzG/j5AdyuHpZVgOvcxVNC7hXvpt4Ngug7f+fnFmYBgfM6E3Yygw5+cFkqpGtmCdBbPSERktQE/WgcdP8m57ZzzpHHi48/PT9J2t0I= Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:4039:2bf1:e8b6:32e6]) by smtp.gmail.com with ESMTPSA id kt5-20020a170903088500b001d70af5be17sm423057plb.229.2024.02.01.17.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 17:12:54 -0800 (PST) From: Douglas Anderson To: Alexander Viro , Christian Brauner Cc: Douglas Anderson , Eric Biederman , Jan Kara , Kees Cook , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] regset: use vmalloc() for regset_get_alloc() Date: Thu, 1 Feb 2024 17:12:03 -0800 Message-ID: <20240201171159.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog MIME-Version: 1.0 X-Rspamd-Queue-Id: 20E3E40009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pghe6rkmbxz9qpjskhfntu8u4b9ok5xn X-HE-Tag: 1706836375-517591 X-HE-Meta: U2FsdGVkX18KXpVdsi3ed+0SPt37oR3mItFond9rgcj7JQoe8V1lvqBvYI6K8wCJHrcVNWRQWxw2sWF177oLJHCE5izthn3zmSYKoQ0uhIy3ShExrqGH4/M3xCTXSY0glP8ba35NKTloS+AhSWB6TaasmeJ+TTF7E1N6rHkHCtDtry9h4fWc4s7snMZG+3O7/1Tf4xiB70Z3VnBzPl5fZU59oRbmJF25sHFpsmYANIiBH1ahxlAanV0a/sENdbtAF/AZLhzP4+PHhTT9/HNwZjrypl8lguinU9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VMBnI4+BM/dkpENI5S1fXL6NL2zZQssT77m+cyobdZdX3+Hm28oei0bvjIbcx5FkQCC38to/ow6g1LOuCUBTdsHAP0Thc3KfWYNFJeSbfI= 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: While browsing through ChromeOS crash reports, I found one with an allocation failure that looked like this: chrome: page allocation failure: order:7, mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), nodemask=(null),cpuset=urgent,mems_allowed=0 CPU: 7 PID: 3295 Comm: chrome Not tainted 5.15.133-20574-g8044615ac35c #1 (HASH:1162 1) Hardware name: Google Lazor (rev3 - 8) with KB Backlight (DT) Call trace: dump_backtrace+0x0/0x1ec show_stack+0x20/0x2c dump_stack_lvl+0x60/0x78 dump_stack+0x18/0x38 warn_alloc+0x104/0x174 __alloc_pages+0x5f0/0x6e4 kmalloc_order+0x44/0x98 kmalloc_order_trace+0x34/0x124 __kmalloc+0x228/0x36c __regset_get+0x68/0xcc regset_get_alloc+0x1c/0x28 elf_core_dump+0x3d8/0xd8c do_coredump+0xeb8/0x1378 get_signal+0x14c/0x804 ... An order 7 allocation is (1 << 7) contiguous pages, or 512K. It's not a surprise that this allocation failed on a system that's been running for a while. In this case we're just generating a core dump and there's no reason we need contiguous memory. Change the allocation to vmalloc(). We'll change the free in binfmt_elf to kvfree() which works regardless of how the memory was allocated. Signed-off-by: Douglas Anderson --- I don't know this code at all, but I _think_ I've identified the places where the memory is freed correctly. Please double-check that I didn't miss anything obvious, though! fs/binfmt_elf.c | 2 +- kernel/regset.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 5397b552fbeb..ac178ad38823 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1928,7 +1928,7 @@ static void free_note_info(struct elf_note_info *info) threads = t->next; WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus); for (i = 1; i < info->thread_notes; ++i) - kfree(t->notes[i].data); + kvfree(t->notes[i].data); kfree(t); } kfree(info->psinfo.data); diff --git a/kernel/regset.c b/kernel/regset.c index 586823786f39..ed8d8cf3a22c 100644 --- a/kernel/regset.c +++ b/kernel/regset.c @@ -2,6 +2,7 @@ #include #include #include +#include static int __regset_get(struct task_struct *target, const struct user_regset *regset, @@ -16,14 +17,14 @@ static int __regset_get(struct task_struct *target, if (size > regset->n * regset->size) size = regset->n * regset->size; if (!p) { - to_free = p = kzalloc(size, GFP_KERNEL); + to_free = p = vmalloc(size); if (!p) return -ENOMEM; } res = regset->regset_get(target, regset, (struct membuf){.p = p, .left = size}); if (res < 0) { - kfree(to_free); + vfree(to_free); return res; } *data = p; @@ -71,6 +72,6 @@ int copy_regset_to_user(struct task_struct *target, ret = regset_get_alloc(target, regset, size, &buf); if (ret > 0) ret = copy_to_user(data, buf, ret) ? -EFAULT : 0; - kfree(buf); + vfree(buf); return ret; }