Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3567814pxb; Mon, 1 Mar 2021 13:36:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfP8+5c6fqWkeKvdhMlUpOzm6quuq2kFPpMGfyM7TQ8wyK2lVc5SXH4cduSqGi8oXxWEjz X-Received: by 2002:a05:6402:4311:: with SMTP id m17mr18287401edc.123.1614634591459; Mon, 01 Mar 2021 13:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614634591; cv=none; d=google.com; s=arc-20160816; b=0FLzJOflujFJPhAvGuwwCJmIoXtQ9pQ5FnUssqtyQWh343o2ak4uANQz9WztIB2jCv E+rW5scBSl4ehuUEIg99q/zybT8XmIeWB0WwxZcm0+sv+mXjjle1nJpEhKwJ5XHgrE8g vKwmOuARCStsoeQgnUofe6xTAR2m1fJNzhRuHgjXLa3OeajXp7S/+4+WzWFOtdnPxELx 5ZYl9/ofDX2OWQcJFJ42Nf/noX7SZJQIea+Bqkpvs727IAcL/zPmDf7UYIVYXq72TrpG RIOz5qNVQNLXmQrN4o7kEw8Pg7FHWTkx6R22EJ5ftETJIDmrkY9CSnGhzuxUhrtR0DGl 948Q== 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=EvGOH7ngJ6BiWOgqKmxfFDu+1X94G8DjAit1Hm4Ptbs=; b=CUroKbLf/Q7nZ1jRENDtPb3sflbYAmbSWvaJv5K52RQ3EwS8zZ1IiUNw09VzJkRJos 1aSBC5HAd7CYguledfeZNzZlwKotsGyto3x+Xf9z9mLTKZjRak4EgdnzovyAPfLiwESw DCLRp1e5bTZMHHmfM79/YLKm+vYFNmAi33beEl9DcMIbw59QqlXbPqQmhLUMcWZqsEi+ M8d1pSO8bNVyw6KgdmiOJmFJWJnoeToCXD03gp/Hefy90FBZuuqd9lO3xk9xydvoNyw9 MW4vEMX3jpVBWmVVNAsv82jeCDw7t7rSnofWhy9gUKCVGmkodq5deCmVhb+KvYsJnUzi UA+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J4mI2TtV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn6si8738727edb.210.2021.03.01.13.36.08; Mon, 01 Mar 2021 13:36:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J4mI2TtV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244295AbhCAVdU (ORCPT + 99 others); Mon, 1 Mar 2021 16:33:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:37350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237347AbhCARSx (ORCPT ); Mon, 1 Mar 2021 12:18:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 77F7D65052; Mon, 1 Mar 2021 16:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617234; bh=7xC4iiMmZejp3ZwjMd4Sr6JX15PfpU1FJ+v4WJcqEw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J4mI2TtVVhd/VqiBN2DlUV1VPhVsZjPyNe+BFWhnMdmcd3ZAvV6BcCgG2MQv/puLS ZjFHQ8jV+Z+K93nnNYHOT/RxBkDKAhTM9+MWQjAeGJ3Qj7Z8Cxmdg6aT8uiK22dSdU BVZbyJ1mbnBnrlUiphc0ca6sgrWrdexalUExRR/4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Elver , Nick Desaulniers , Nathan Chancellor , Fangrui Song , Jessica Yu Subject: [PATCH 4.19 224/247] module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols Date: Mon, 1 Mar 2021 17:14:04 +0100 Message-Id: <20210301161042.653694736@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fangrui Song commit ebfac7b778fac8b0e8e92ec91d0b055f046b4604 upstream. clang-12 -fno-pic (since https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6) can emit `call __stack_chk_fail@PLT` instead of `call __stack_chk_fail` on x86. The two forms should have identical behaviors on x86-64 but the former causes GNU as<2.37 to produce an unreferenced undefined symbol _GLOBAL_OFFSET_TABLE_. (On x86-32, there is an R_386_PC32 vs R_386_PLT32 difference but the linker behavior is identical as far as Linux kernel is concerned.) Simply ignore _GLOBAL_OFFSET_TABLE_ for now, like what scripts/mod/modpost.c:ignore_undef_symbol does. This also fixes the problem for gcc/clang -fpie and -fpic, which may emit `call foo@PLT` for external function calls on x86. Note: ld -z defs and dynamic loaders do not error for unreferenced undefined symbols so the module loader is reading too much. If we ever need to ignore more symbols, the code should be refactored to ignore unreferenced symbols. Cc: Link: https://github.com/ClangBuiltLinux/linux/issues/1250 Link: https://sourceware.org/bugzilla/show_bug.cgi?id=27178 Reported-by: Marco Elver Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Marco Elver Signed-off-by: Fangrui Song Signed-off-by: Jessica Yu Signed-off-by: Greg Kroah-Hartman --- kernel/module.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) --- a/kernel/module.c +++ b/kernel/module.c @@ -2274,6 +2274,21 @@ static int verify_export_symbols(struct return 0; } +static bool ignore_undef_symbol(Elf_Half emachine, const char *name) +{ + /* + * On x86, PIC code and Clang non-PIC code may have call foo@PLT. GNU as + * before 2.37 produces an unreferenced _GLOBAL_OFFSET_TABLE_ on x86-64. + * i386 has a similar problem but may not deserve a fix. + * + * If we ever have to ignore many symbols, consider refactoring the code to + * only warn if referenced by a relocation. + */ + if (emachine == EM_386 || emachine == EM_X86_64) + return !strcmp(name, "_GLOBAL_OFFSET_TABLE_"); + return false; +} + /* Change all symbols so that st_value encodes the pointer directly. */ static int simplify_symbols(struct module *mod, const struct load_info *info) { @@ -2319,8 +2334,10 @@ static int simplify_symbols(struct modul break; } - /* Ok if weak. */ - if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK) + /* Ok if weak or ignored. */ + if (!ksym && + (ELF_ST_BIND(sym[i].st_info) == STB_WEAK || + ignore_undef_symbol(info->hdr->e_machine, name))) break; ret = PTR_ERR(ksym) ?: -ENOENT;