Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2189170iof; Tue, 7 Jun 2022 22:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ076z8NV1T0si31/SsX/vBcpsHZYy24Lz8DuNkHO9eCDXoY+MOhSFgQ617XKBcAS7CLCa X-Received: by 2002:a63:2f84:0:b0:3fc:5ffd:ee6c with SMTP id v126-20020a632f84000000b003fc5ffdee6cmr28152692pgv.163.1654666694023; Tue, 07 Jun 2022 22:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666694; cv=none; d=google.com; s=arc-20160816; b=GcDsvTb6CNFFpikSKUTOHDBrMMlu79FXX4d8Ba2b19dNopToZ8+35Tb5yph5fhGt9w fzyOfDCRScDjLRt2rtPpJx/QjCzUVMwVisrgZ6+dgFrFffL5x7SEq6+yFGVi6sf1bVeF cFFakdfHUgQnV4q+k+y+VvSbUcnCbAD+k3KJTPSDNbdUbfLJQMdoWlJ4is6rSdbpXMl8 U2GScm3VDgLN1X/rzhZJd0S4OVnDa90fGXeJgqTB+seQBNB9mGqZpPOv0n6ESq/drhqd +FBJjWOXlcksNbLj4L+E5UJXMEUm86hQdMIlAdUcrmtNYPLU3Xci5vMjhJtZ9bgwmBUY GRPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gAS0t8wo+4hBfgjGx9qUy1LkCfXA97ardg/0TmBN/Ow=; b=mHNcHiY5o2yEbzjHyhm8hb2tJ2E2xSonJqUrcma3lqray4biQvpVxsbM3y5RlAy/FO RlCkxfVQ0E1bmItqo2JeWALJPukGA5QZM/ai8KBPTJOFRZ0s5jaPMZPZqZi+B31GlY+i jhelc6GQKTPH6AyUENlHsJQEkR3AGSTcMuP0HhoWbTuxHDGOClIsRo2qsTHbLJvuINY1 MkgiU8R2x0pe0tSy5AbcYdCJDyAdhdHqUF1xURQuSjLFpmXlc51AK6/nWlrS9N3KJWKX GH4MNYNIPo3+4KSJ/ROGtIsWrOOYoqJZPuxF8tPobkzyf5K6a0B+YyXx7rMmdUYYBPTh PwkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=puvmC65i; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c10-20020a6566ca000000b003fc7f8ccf26si28466304pgw.89.2022.06.07.22.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:38:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=puvmC65i; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61D6349EC66; Tue, 7 Jun 2022 22:13:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388690AbiFHAcm (ORCPT + 99 others); Tue, 7 Jun 2022 20:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382702AbiFGV7i (ORCPT ); Tue, 7 Jun 2022 17:59:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 267EF24E009; Tue, 7 Jun 2022 12:14:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F3E056187F; Tue, 7 Jun 2022 19:14:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A428C385A2; Tue, 7 Jun 2022 19:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629241; bh=5NVwfizFJYa+rVoBcHgPIn0dLHQ3kWh10mrNptlL5ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=puvmC65iLdPQEPaDzBB6WZ+9hwWLdiYexgbeKbCiT8CQNA3n/olqlt3DcsogJQYQl g0dlelLIFyj9EE2Zins/eJJ2CtCYGjsg+nd3HDxNpQd31q4AMk3D3c53s2D8i9Kxy6 YpvP/fKtAs9Hp5Idre44q0LRsIjN9LhCS9dBnM18= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Dobriyan , Luis Chamberlain , Sasha Levin Subject: [PATCH 5.18 619/879] module: fix [e_shstrndx].sh_size=0 OOB access Date: Tue, 7 Jun 2022 19:02:17 +0200 Message-Id: <20220607165020.817539600@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Dobriyan [ Upstream commit 391e982bfa632b8315235d8be9c0a81374c6a19c ] It is trivial to craft a module to trigger OOB access in this line: if (info->secstrings[strhdr->sh_size - 1] != '\0') { BUG: unable to handle page fault for address: ffffc90000aa0fff PGD 100000067 P4D 100000067 PUD 100066067 PMD 10436f067 PTE 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 7 PID: 1215 Comm: insmod Not tainted 5.18.0-rc5-00007-g9bf578647087-dirty #10 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014 RIP: 0010:load_module+0x19b/0x2391 Fixes: ec2a29593c83 ("module: harden ELF info handling") Signed-off-by: Alexey Dobriyan [rebased patch onto modules-next] Signed-off-by: Luis Chamberlain Signed-off-by: Sasha Levin --- kernel/module.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 6cea788fd965..6529c84c536f 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3033,6 +3033,10 @@ static int elf_validity_check(struct load_info *info) * strings in the section safe. */ info->secstrings = (void *)info->hdr + strhdr->sh_offset; + if (strhdr->sh_size == 0) { + pr_err("empty section name table\n"); + goto no_exec; + } if (info->secstrings[strhdr->sh_size - 1] != '\0') { pr_err("ELF Spec violation: section name table isn't null terminated\n"); goto no_exec; -- 2.35.1