From nobody Fri Nov 29 04:51:28 2024 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E10A21AD9F5 for ; Tue, 24 Sep 2024 21:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727212855; cv=none; b=n49eu4rJEdgqxO8IyVpHUkVZZG6AAD6Y+EasYpET9xIOBIk8xDsA5lKbXe0jVZ71GtKuQNc7e+LeU/dzUlFSJ9U1vc2MT/uZR06X/ma3xfnnbPDqagM4lfcM8Bo/2RtRzALZaaX3dFKBY9KYUJisjSVaDD3cQ6A06fZCQm42ZeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727212855; c=relaxed/simple; bh=RFwYTaeqemLtmezDNnI4k0C/4IQdB480nO3xNfeeufc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=h2Lx7RYtX6RT/A1h9+GuIV5i7uPxQ8/FhHCBdNP6DzNk90663hLj7ttc0SB37sMTrtilSlePsDDMPamO8yayIJmXptJNptOmY5eXGyLj5ASH21020Bq9UIKJilCRUOXPUZVlnpJ7h3tguurBzRuYImBaM2ky8RGr91Ohfa7CULQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YTb6CuKW; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YTb6CuKW" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7d4dee4dfdcso6050088a12.2 for ; Tue, 24 Sep 2024 14:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727212853; x=1727817653; darn=vger.kernel.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=extRuG4D1AdoHKvsMv2fLx/d2D/gEpHsXYLRVzC3Sa0=; b=YTb6CuKWLfVSW6kYzTb/oJq5vhfBFvXiQgvZKTAtmUBcHjaP71872uRp5nrTcl2loN G9KSbeXhAPSf1+omyUm/XiKdKTk/EZnX5wDrh8g95QtBLPEOi7CzZ9eZ/BKdfVNy8wqQ X58bmBme48AMBeMwhhO5cZYb5M2Vmghk6uqLIzQwlGsNt5zCWq57coMBLYaq+vQ7Cjw1 pCyrGrehzONRs+2THALe8aMmxhx84Uhz6vfIaYwYBuopm1j9IEPtJLnh1ZRui5Rgi3TG lfKjEy2vdIBU0aUynAeR0tnNv+xN5z6QDUWFGbYfuSJMFCbbZyIfgNqtJ4CwqtWfP0RZ WoBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727212853; x=1727817653; 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=extRuG4D1AdoHKvsMv2fLx/d2D/gEpHsXYLRVzC3Sa0=; b=DA8hq0iUsQRDoo4JgkHUi5qEeGBH8LaJWPjoZ5RPWndTtOVhuHv1VgvdD62hkd5nID g+t1n0rhP4sAmGY7ASOQUVlNm5ocWh0q0XqCWsvOHhI2BWvmXPm38Z4kcwoi1TwvB4Iv uBNfC0UtAENzISbVJ4NVuXypmDBhsKTOVCneRk2SGlWDkyVlpo2z0TO4qlrJuyyyBDku Bp7s+VKchEF2mumCngBhAA4LkVDTnsCyAr2s4PqEi23Pc2ybYiX2Fz9PFhEy4ZQqFgmX IYU6mU8pLn9xXK6PEVpcHa9ckTHxks3F4pxrzPepx+iqLCZeuA4siomeYMoo5gahDhy5 zKqA== X-Forwarded-Encrypted: i=1; AJvYcCVeSSTjq5NzFaZPQ378aFdxcsQQFcr6mTnfQ29Fnk3OAMhUbA5vvaOjkzRmy7RXT01c2ISNg+3AuAZitME=@vger.kernel.org X-Gm-Message-State: AOJu0YzjUBtXPKb0BcD1ScdQIgIyi9TP23m8R8H749Ist7/R8MUNkbsj ucMDrIeQmoRWtC/meL6IHlYiHvZ2HflZoKdtd8ll0rUbpcm6zkxzFzVTE4JnGRT9MBq7Gto9PEP 6bwWYtA== X-Google-Smtp-Source: AGHT+IE3L8DCbOXBbulDlaKBgDSXwFgtzL3CsvCHzYn0GW9XmpM352NgTobVLRsi4oRtR0Auru991pms+fQd X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a63:2403:0:b0:7cd:8b26:15df with SMTP id 41be03b00d2f7-7e6c196835dmr1649a12.7.1727212852738; Tue, 24 Sep 2024 14:20:52 -0700 (PDT) Date: Tue, 24 Sep 2024 21:19:52 +0000 In-Reply-To: <20240924212024.540574-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240924212024.540574-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Message-ID: <20240924212024.540574-11-mmaurer@google.com> Subject: [PATCH v4 10/16] module: Factor out elf_validity_cache_strtab From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Alex Gaynor Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, Matthew Maurer , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Boqun Feng , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , linux-modules@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch only moves the existing strtab population to a function. Validation comes in a following patch, this is split out to make the new validation checks more clearly separated. Signed-off-by: Matthew Maurer --- kernel/module/main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index e04a228c694a..c082d5d41a8d 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2089,6 +2089,23 @@ static int elf_validity_cache_index(struct load_info= *info, int flags) return 0; } =20 +/** + * elf_validity_cache_strtab() - Cache symbol string table + * @info: Load info to read from and update. + * Must have &load_info->sechdrs and &load_info->secstrings populat= ed. + * Must have &load_info->index populated. + * + * Return: 0 on success, negative error code if a check failed. + */ +static int elf_validity_cache_strtab(struct load_info *info) +{ + Elf_Shdr *str_shdr =3D &info->sechdrs[info->index.str]; + char *strtab =3D (char *)info->hdr + str_shdr->sh_offset; + + info->strtab =3D strtab; + return 0; +} + /* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go. @@ -2122,9 +2139,9 @@ static int elf_validity_cache_copy(struct load_info *= info, int flags) err =3D elf_validity_cache_index(info, flags); if (err < 0) return err; - - /* Sets internal strings. */ - info->strtab =3D (char *)info->hdr + info->sechdrs[info->index.str].sh_of= fset; + err =3D elf_validity_cache_strtab(info); + if (err < 0) + return err; =20 /* This is temporary: point mod into copy of data. */ info->mod =3D (void *)info->hdr + info->sechdrs[info->index.mod].sh_offse= t; --=20 2.46.1.824.gd892dcdcdd-goog