From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 0EBD080031 for ; Thu, 26 Nov 2026 06:13:24 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ6CCOW006059; Thu, 26 Nov 2026 09:12:13 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6CCOW006059 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="FydtbRBA" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ689RQ005417 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 09:08:10 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ689RQ005417 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c4d4d132bbeso617394466b.0 for ; Wed, 25 Nov 2026 22:08:10 -0800 (PST) X-Gm-Message-State: APuU4Z9OEwUr9AKBxwvkcn7QwfbHSiuyHdBrlR8Mz24T2JX5YY61wi6h 1MSWeCkhssHXr3JK6xhHju56zAddCt51b/q/P73nGgVEJh+BnHPRGZbYm68NHX5K7tqjKFnBf/E 9bhAWv4jCe1QQ2rxWOOV8sWv11HkqIOYn0OLjDcb6j5pIO/qDKHUfbA== X-Gm-Gg: AZFdTZeuoID4GnPdlBVCMXijum1kCxTQ0okpEDfM4bL9S0fr9+BVdr5WSW8B3Iqkdk/ /nEujnE87CBB0lTfUKZhSdJksF1C7zmXg2V58bmXiOm9mdMI6cj3X6/uGxIgDUTS0VGKETI6ZIr exd0eYpbvcaT5mQmVZ7IJSxSsjhLb/rcMaO5xdiBRvnb+Io6P/yC9MaLNI3Lhpo+PeEFrJVuSES o1VZbhBDboJE3m3rwpaXuO0FBAFgHgF94CFCJfymweh4Rcwq1amlNGc7KdEfLBu7IE8r98vqeKB xhCY8E8Ax6XqsknyyNJ8Emll3/TPhmMzSPK+sj8AvmYETmpZZ1kkhU6kZ7aVrsO/01l913DPyOh NyERxzxdEX1JHF9R4tTfuaPJ7 X-Received: by 2002:a17:907:3f18:b0:c46:9711:e30e with SMTP id a640c23a62f3a-c5131a1601amr1699482166b.29.1795673289675; Wed, 25 Nov 2026 22:08:09 -0800 (PST) X-Received: by 2002:a17:907:3f18:b0:c46:9711:e30e with SMTP id a640c23a62f3a-c5131a1601amr1699481266b.29.1795673289265; Wed, 25 Nov 2026 22:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795673289; cv=none; d=google.com; s=arc-20260327; b=G51yfnDOzXl6rKdpkqAn7yfP2YqEmgXA5VW7rJzWwnSH+d+jsfotMKNePVxWfqedaW etqrjGHCmTQcHvEUY22JDCmRp2SUBEz6YJNyuPSRLXIjkOkDgb+s50BVNjfIUYpO2Ydp Y+H89XlCodT+sjji8It3KFc5VsOyArHridM51H65OG3dCREqUDUiVfefbSlQra7MGDcY sZR9QTOWWgJX5byAeZPNbE8jgcd+vC8Yv223IKygXiyqPqq3XNVm+zAinTcIbyj5DWDY Gy+fwH6tiMLLOtBCG1R4X2TSrWd03tGg1tLf2Cl/WB/UrdiHYy8rmcn510tCIp7zZoJ6 1EPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=5lRAbQBvPW1UowTjBovw7v3dLEXhGi97XkUgz44s3lA=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=J7jT0mo7i7cMW0raGhYuigVMRZ2ZaeUmRY62cT7mco3RchgJ2TZyirTARvExo2g6cg 7BmGsFet7Dvq62UWjOdh+FsfnDMDNtbzrvQFLecyZ/+q+XAzkd1RyJF7aELYHFIsW6X4 Yl6ksRrjGh+Oq09FoB3ii91OLa8ZwpumgZZXDlLicsCY9tjwyL3+cZx67qEtykD4i50R P3zMUQIUAruj6qB1GmvR4G4vC+yyAsEOrm8mI7UqtbX/RNkkm937shWWquGkgBCcmsxp yqHMUquJeqtJyyLblRluT5LXzebwCqRbBda4GQj5SfmDfpr20cZXQPlvXBDQInaXOV8X MMqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=FydtbRBA; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513afe3a64si1279369566b.85.2026.11.25.22.08.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 22:08:09 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=FydtbRBA; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=5lRAbQBvPW1UowTjBovw7v3dLEXhGi97XkUgz44s3lA=; b=FydtbRBAn3kF Boy3aONMh8Va6GKZ9+oVNMjoThdXVT2n5ByJq3uMLWP3z2kOo0IpOuNazqjrCM2XY858dN5wuofUN IRTOBWeaVbF1GH9B01CXiGWIor/qIBacc6LerPVk+W+dewUgOfWHwg7reW3GX/1Y3UGiZ5UK/oqKQ Ft2YK++bUUq6wwrSZQaRCpj/CwSTY8Isz3wb/J1c886E/RUTtJREJoXbMnBDL7qvX2i5vqdARQNDA 6u4VuMzwb3Xwyn643qFWPXBYw/7ZoMgGDZ5LnjBWSs1JGR/4g3ati4p5wHuUA5k0a2PgYKLOoishP oq0WQNmhqQfpcfWLwfjd9g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWSct-00E8nT-1s; Thu, 26 Nov 2026 07:06:46 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 26 Nov 2026 07:07:26 +0200 Message-ID: <20261126060620.2126341-29-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> References: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 27/28] ms/objtool/klp: Allow new references to module exports X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Joe Lawrence klp_reloc_needed() returns true for module exports to support late-module patching. However, clone_reloc_klp() unconditionally rejects symbols without a twin (i.e., new references added by the patch), even when the symbol is a known export from Module.symvers. Relax the check: allow new references to exported symbols by only erroring on !twin when there is no export. The export metadata from Module.symvers provides sufficient context to emit the klp-relocation without a twin. For a module export that isn't sufficient on its own though, as the resulting klp relocation will only be resolved at patch-enable time if the exporting module is loaded. If the original (unpatched) module already depends on the exporting module, the dependency is safe: the module loader ensures the dependency is satisfied before the patched module can be loaded, so the klp relocation target will exist. However, if the patch introduces a reference to a module that the original doesn't depend on, there is no such guarantee. The exporting module could be absent or could be unloaded at any time, leading to a relocation failure or use-after-free. So also add a build-time check: when a new symbol reference (no twin) targets a module export, verify that the original module already has at least one UNDEF symbol resolving to that same exporting module. If not, error out with a diagnostic message. Signed-off-by: Joe Lawrence Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/e0d725acb4774747f0e271308b4ca33daae2d5db.1786138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf (cherry picked from commit 72d76d0c18ebd40f6a32df875ff40528564849c1) https://virtuozzo.atlassian.net/browse/VSTOR-156924 Feature: klp-build support Signed-off-by: Eva Kurchatova --- tools/objtool/klp-diff.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 7eac2ef0f73d..066dbe69c709 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1001,6 +1001,28 @@ static int convert_reloc_sym(struct elf *elf, struct reloc *reloc) return convert_reloc_secsym_to_sym(elf, reloc); } +/* + * Check if the original module already has a dependency on dep_mod, i.e. it + * already references at least one export from that module. + */ +static bool has_module_dep(struct elfs *e, const char *dep_mod) +{ + struct symbol *sym; + + for_each_sym(e->orig, sym) { + struct export *exp; + + if (!is_undef_sym(sym) || is_weak_sym(sym)) + continue; + + exp = find_export(sym); + if (exp && !strcmp(exp->mod, dep_mod)) + return true; + } + + return false; +} + /* * Convert a regular relocation to a klp relocation (sort of). */ @@ -1019,8 +1041,17 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, unsigned long sympos; if (!patched_sym->twin) { - ERROR("unexpected klp reloc for new symbol %s", patched_sym->name); - return -1; + if (!export) { + ERROR("unexpected klp reloc for new symbol %s", patched_sym->name); + return -1; + } + + if (strcmp(export->mod, "vmlinux") && + !has_module_dep(e, export->mod)) { + ERROR("%s: new reference to %s (exported by %s) would create an undeclared module dependency", + patched_sym->name, export->sym, export->mod); + return -1; + } } /* -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel