From mboxrd@z Thu Jan 1 00:00:00 1970 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 5C3041E9B3D for ; Wed, 8 Jul 2026 01:21:25 +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=1783473686; cv=none; b=TiPSw6wEZItfQ6X42DbrmpvlN2mUDUCZhZOzCYN6eMV+3Cs8jqSKarpVVrYdPXmhK+pYZKk3SmHh8sGiBhh91Tes8rRKey99Stlnv28iAU9Pinq4+ydjTFCaVlJ82cAORM5luhQQuSLJGsJ9mD4GBBXaP60lDcotzTs95O1KXTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783473686; c=relaxed/simple; bh=0iDTC6iQ7HU2MRhmbhyR3vQ+Xx/rnAbImlk5nSbmjrI=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ugrtgYOH+iny5bsVbJe0Boo2snAQINZY6sxgHz6bQM+3Cr+slsKayLNNRClktbtvW5IacypjnsdcxZghgrb5w+tuEG9gbCQ9yqA+HExffRLebdUFSKpFyWFZtAlPENU0XuH1ISQNjYRsdg4IktYo00Lrwzsj753GAtXvI/vtSC4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tweek.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gxv/QB00; 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--tweek.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gxv/QB00" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c8895156101so161513a12.1 for ; Tue, 07 Jul 2026 18:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783473685; x=1784078485; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=49r50tPsVjGlL5O8jUrDgUaT0UYvkKRZ1jOzYL8QtlQ=; b=gxv/QB00cWmFuFZCNTCCvh/S4FAH81kd665Ipt6qhyqqVtDidmUlG9Mtov3qR4rEH3 3vim1RneqCYqL4XUAwQ58m6+s+W5R5EHtl0IFViHet0LXxANTLKAimK3UAMoxXcuFA4z w0v9EZdeqUx0XQbvMJujfpvM1908CI/xaqTeboNuBF25QfWzrdHHD7bnzwDCaBEf/+2q B5UX6lOKm+u9WrrSifGKkp4/HkE32yx0dbT3NJAXA4vGGsxVufYIabcQb7Jc5uJhushO S60u/e/+xWCVepW17odDI2LWYjxQOZXJHYko6xbKeyIMmSQNfVWxu7fWSlNLWhUTQdl0 nIiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783473685; x=1784078485; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=49r50tPsVjGlL5O8jUrDgUaT0UYvkKRZ1jOzYL8QtlQ=; b=FWorLEvbDzC/YENWz0T53PJkkRJDO4SGB+oS6hCojtZ1VTgzDovVRsLb0nPWQYxeDq cXclBQaLVSVeJE6zlPDb1poIoS4YWSjJWnNXberCbwoq+0xZV57TDIylpM7rOAZ4LaDc j1shUs6NOj5tY4Cf5Nyk/D81tifDJRT/SH7gwL9B93Q6pOJBTVJ1Ioaywm4h5Nc/Bme0 eKKbwdLHlBqFubg7EKyA9hZteqKwU3i5y4JEQp+nmd2mL7WvM7R8NY6PKxgXGJ4p1XcK 4tOrgJytCW2yr7GAl2EZQkFpeSKk413U5Rx5x9H4HAUIM/hkNWFB/fMuXyH1v/Xru0WI Hmhg== X-Forwarded-Encrypted: i=1; AHgh+RpKeJmUuuDehr9zKI5FXuJ0Y/tiFiDZUMv0dysx/1K4e/VqDNktKPeQkjuNX9Z/sndJy63LkOzNYEpG+UM=@vger.kernel.org X-Gm-Message-State: AOJu0YzekW0mOiOWEW5iUNmwHwZy1zXOnHHgINjlKLvBDVJ6FS56AJLa dr4L+gWnwSq0cM44W0MVmVy6BRaEbm+b+1YyEDTEtHx6csPW8yvqePcYdurpZCI0Sv1+vO+bkKs 5jQ== X-Received: from dldyr15-n2.prod.google.com ([2002:a05:701b:450f:20b0:139:b637:8de6]) (user=tweek job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a9c:b0:3bf:9c93:ac44 with SMTP id adf61e73a8af0-3c0bcfea4bcmr140843637.19.1783473684556; Tue, 07 Jul 2026 18:21:24 -0700 (PDT) Date: Wed, 8 Jul 2026 11:21:07 +1000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260708012107.1621513-1-tweek@google.com> Subject: [PATCH] module: validate string table section types From: "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , Aaron Tomlin , Siddharth Nayyar , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable In elf_validity_cache_sechdrs, section sizes and offsets are validated, unless the section type is SHT_NULL or SHT_NOBITS. Later, elf_validity_cache_secstrings and elf_validity_cache_index_str access the section name table (.shstrtab) and symbol string table (.strtab) headers without first ensuring that their types are SHT_STRTAB. If a section type is SHT_NULL or SHT_NOBITS, sh_offset has not been validated and may reference out-of-bounds memory when dereferenced in elf_validity_cache_secstrings or elf_validity_cache_strtab. Validate that both string section headers are of type SHT_STRTAB before caching them. Signed-off-by: Thi=C3=A9baud Weksteen --- kernel/module/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 46dd8d25a605..7cbc8f0e28c6 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2011,6 +2011,7 @@ static int elf_validity_cache_sechdrs(struct load_inf= o *info) * Specifically checks: * * * Section name table index is inbounds of section headers + * * Section name table type is SHT_STRTAB * * Section name table is not empty * * Section name table is NUL terminated * * All section name offsets are inbounds of the section @@ -2038,6 +2039,11 @@ static int elf_validity_cache_secstrings(struct load= _info *info) =20 strhdr =3D &info->sechdrs[info->hdr->e_shstrndx]; =20 + if (strhdr->sh_type !=3D SHT_STRTAB) { + pr_err("Invalid ELF section name table type: %u\n", strhdr->sh_type); + return -ENOEXEC; + } + /* * The section name table must be NUL-terminated, as required * by the spec. This makes strcmp and pr_* calls that access @@ -2204,7 +2210,7 @@ static int elf_validity_cache_index_sym(struct load_i= nfo *info) * Must have &load_info->index.sym populated. * * Looks at the symbol table's associated string table, makes sure it is - * in-bounds, and caches it. + * in-bounds and of type SHT_STRTAB, and caches it. * * Return: %0 if valid, %-ENOEXEC on failure. */ @@ -2218,6 +2224,12 @@ static int elf_validity_cache_index_str(struct load_= info *info) return -ENOEXEC; } =20 + if (info->sechdrs[str_idx].sh_type !=3D SHT_STRTAB) { + pr_err("Invalid ELF symbol string table type: %u\n", + info->sechdrs[str_idx].sh_type); + return -ENOEXEC; + } + info->index.str =3D str_idx; return 0; } --=20 2.55.0.795.g602f6c329a-goog