From patchwork Fri Nov 1 00:00:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13858510 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 AE008E67490 for ; Fri, 1 Nov 2024 00:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0426B00A2; Thu, 31 Oct 2024 20:00:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A05B6B00A6; Thu, 31 Oct 2024 20:00:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 168B16B00A7; Thu, 31 Oct 2024 20:00:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EAB556B00A2 for ; Thu, 31 Oct 2024 20:00:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 905FEAD228 for ; Fri, 1 Nov 2024 00:00:23 +0000 (UTC) X-FDA: 82735568454.15.1BBAE03 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf01.hostedemail.com (Postfix) with ESMTP id 3C89940010 for ; Fri, 1 Nov 2024 00:00:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="DiLGaEC/"; spf=pass (imf01.hostedemail.com: domain of 3FBokZwYKCBkHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3FBokZwYKCBkHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730419006; 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: references:dkim-signature; bh=1E3qJdavv7fjHbqyvEFCACtggtWj/ztsb6CTdBP0XOU=; b=v7ydkY0pwVCm/SGYM/k955SD+hLvznjGME1sRQ7wTjwQEji0kMiHeE1xaMuIQ+gS/wfYYz tfwNTVULWKPb82Aj6Qg1t93wrXCQoOPjBd8fbgPyv384ZbTdGpZFN2mM8axUOSn54S30C+ zqiTS4sdP+P+l5NMjkXFpMH0+GYB3WQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="DiLGaEC/"; spf=pass (imf01.hostedemail.com: domain of 3FBokZwYKCBkHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3FBokZwYKCBkHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730419006; a=rsa-sha256; cv=none; b=T+MC9FeXA4hUr+vfO2iO2JlYOVyWW7zN6B3kt2Pttq060iAQfQPk6ze+w/gYkVfkY/ng7M WB2NUzGhuFru730XwQhg3gEMW+W+a9YuNpObXQ+YiLLGR5dqCytLxFZJhc5mc6uGDtGZMn lqhd5pPUydcVJhIieCWC4nA54DhWW6k= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30cd709b40so2618882276.1 for ; Thu, 31 Oct 2024 17:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730419221; x=1731024021; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1E3qJdavv7fjHbqyvEFCACtggtWj/ztsb6CTdBP0XOU=; b=DiLGaEC/iuyOsnk2rbQ3SSV6dtHVBUpPUfdwp7E8iViw78EzmwLRkLrbw0H7uUnQti 8uZXNkve51K8Y5a+NYdvT3nJULX3uFElBXNDu4906MUMqUzlepavKUucNJjfojaINMaq u3oaT1R5WoZwYd6Z517SC39CJO0n7+89IsQLYQROI9xNAdaSIH1/u3KZ8QWaJCmMALrt 7+Z4DNuGy1LOOREzXjKFobXm3YLWHAJyHk5IOFaiCK/ynkEKAIauepB8x8f5GNt6cV8T /lhnkOg5MoTZJKnP6nP7/WAY3AIRs+GCMGO16AZIEuu/zHRExphm0e1EGpbWe2iFeJHr /Scg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730419221; x=1731024021; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1E3qJdavv7fjHbqyvEFCACtggtWj/ztsb6CTdBP0XOU=; b=VGD5nd2miTNi+FznP59alroI64Yy9L3+rC9VD2VL+JK6qeVnePReUPadl+sebralnu e5Ag5pf1UyDuh6WksNsChMFY5P/LJz8B+VKtPXQVxoLUyvHj2jVDdUnW+G6JV/AvTW6t 0DprjedHszhM7LtP+ivG6NL3BdSWj8mdywah8MMow9kc4zYH7OLi+qhXOVPRvtNCK+Sf HuiJMu/Lc60F+7kEaQ3Bbs+/f1i4s2AbFXVj2XmWcjer51WX5Youiz0FQvO5SBayNVvS lCCqISc+tUhJjPEFnCo+ciBAtYlu0enPymEPdEW6qbiNP4guVwHd0O2N8Bhed/15+Y2x 1ZwQ== X-Forwarded-Encrypted: i=1; AJvYcCXPR6hG5lNaCOi9XQ5lSGmz8tiz7L7T/pzIC81Izi2zhjKIGh2E2tpohhcf4MYZ5AF5XvVLBC/Fiw==@kvack.org X-Gm-Message-State: AOJu0Yz1eoqcQcCk+Att/2ZeN1BkTb7Ylp56r0FRgP5EzOV9W7SzR9jX VzPRUUMtWEzh9p8Qh+bEpnYoj9noe3NWw8DU8x/wX7mj63MJyoUOvldwzvkfrZwopSU7/gnO8sj IWA== X-Google-Smtp-Source: AGHT+IG27m+WkXwA4bhIP2BQ4mgmMvXs/r783mfj828zYLixBTSb4bhAFRNU29d41c5oUeeHYirxFASbVfo= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:1498:a594:2b5d:75e5]) (user=surenb job=sendgmr) by 2002:a25:ea48:0:b0:e30:d37d:2792 with SMTP id 3f1490d57ef6-e30d37d2919mr14776276.0.1730419220629; Thu, 31 Oct 2024 17:00:20 -0700 (PDT) Date: Thu, 31 Oct 2024 17:00:17 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101000017.3856204-1-surenb@google.com> Subject: [PATCH 1/1] alloc_tag: fix empty codetag module section handling From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, dan.carpenter@linaro.org, rppt@kernel.org, mcgrof@kernel.org, petr.pavlu@suse.com, samitolvanen@google.com, da.gomez@samsung.com, yuzhao@google.com, souravpanda@google.com, pasha.tatashin@soleen.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3C89940010 X-Stat-Signature: hmmiygu99gfpwgdgh5wj8udr4omzk9cp X-Rspam-User: X-HE-Tag: 1730419200-987967 X-HE-Meta: U2FsdGVkX19jluyx9LqHcLGWh8MZhMzz/Lc7iSZGNd/0YeUiLkZw0hi5otK2Tcrhz0/lmQkyfiSwF+hQNhkws8jNRdwIgeuLzo55j0qiFdi5ghsnncZUaZVfSMtoXZkz1mzT6UMDkpGzQpT2U6NaBcqRgsOvnu9NfOvAQ7GxxaLX/okVpxfyOXqde0wioi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zbxjTrFOS1SzlH7TRyUfmBAZTmvADuwstz5x3nOq8MuhZTgsMYMy4eRXOtgz1k/uwPOXIDudUejw7roamGREcNctWqmB/6mXrQDh8iLCUpC2gKfIM7w1hKoH17t10/SCFs8ybXAU/WiEFC5IIEr90/6z9v44zWoVuuY6aPtTD6e6iGT1SbbAsjT88ZjUh0gkQ9jCu3nXW1LXMJV2Bvh3YxVho6xF8tJQqmAtJi49Yl14zCGKrh57/uRZgJSkCiaRzfX9M80rrp/bkVaP3cwy62f1HxfTs9ccLm52FTDpn+F/Yz6h7n64LgXNvnxy1qaxC3wTQQG/I+K6N+YmX2IMwUNJz1F7Y2aciA6pUe1YU7GHwk9pmn8wRNsm6HIqMPtlGaOJ9V+bwoJDApyHvlNhsjf8h4= 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: When a module does not have any allocations, it's allocation tag section is empty and codetag_alloc_module_section() returns NULL. However this condition should never happen because codetag_needs_module_section() will detect an empty section and avoid calling codetag_alloc_module_section(). Change codetag_alloc_module_section() to never return NULL, which should prevent static checker warnings. Add a WARN_ON() and a proper error reporting in case codetag_alloc_module_section() returns NULL, to prevent future codetag type implementations from returning NULL from their cttype->desc.alloc_section_mem() operation. Fixes: 61c9e58f3a10 ("alloc_tag: load module tags into separate contiguous memory") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/50f12fa1-17c1-4940-a6bf-beaf61f6b17a@stanley.mountain/ Signed-off-by: Suren Baghdasaryan --- kernel/module/main.c | 4 ++++ lib/alloc_tag.c | 2 +- lib/codetag.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) base-commit: 758db9ca0107bc6c00f0ed4808974d66c8dc2fea diff --git a/kernel/module/main.c b/kernel/module/main.c index 129c98e6380d..00c16f5c5568 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2316,6 +2316,10 @@ static int move_module(struct module *mod, struct load_info *info) if (codetag_needs_module_section(mod, sname, shdr->sh_size)) { dest = codetag_alloc_module_section(mod, sname, shdr->sh_size, arch_mod_section_prepend(mod, i), shdr->sh_addralign); + if (WARN_ON(!dest)) { + ret = -EINVAL; + goto out_err; + } if (IS_ERR(dest)) { ret = PTR_ERR(dest); goto out_err; diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 1c74942e6dfd..00ab18ea452a 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -437,7 +437,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size, /* If no tags return NULL */ if (size < sizeof(struct alloc_tag)) - return NULL; + return ERR_PTR(-EINVAL); /* * align is always power of 2, so we can use IS_ALIGNED and ALIGN. diff --git a/lib/codetag.c b/lib/codetag.c index 4949511b4933..42aadd6c1454 100644 --- a/lib/codetag.c +++ b/lib/codetag.c @@ -244,7 +244,7 @@ void *codetag_alloc_module_section(struct module *mod, const char *name, { const char *type_name = name + strlen(CODETAG_SECTION_PREFIX); struct codetag_type *cttype; - void *ret = NULL; + void *ret = ERR_PTR(-EINVAL); mutex_lock(&codetag_lock); list_for_each_entry(cttype, &codetag_types, link) {