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 56C5680032 for ; Wed, 25 Nov 2026 06:14:14 +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 6AP6D3bx016194; Wed, 25 Nov 2026 09:13:03 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6D3bx016194 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="QB6SlhbC" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6CmCX016112 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 09:12:48 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6CmCX016112 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c506f007ae2so510971066b.1 for ; Tue, 24 Nov 2026 22:12:48 -0800 (PST) X-Gm-Message-State: APuU4Z9F7kvIbI+zVWqwO38Xa817dAU+4tjzw4BMxo1ghvBVeDMmrkRH nkrbd3B0G4LpfB87lQHmoOlT2UEvW54GXd/DRlfFtkOONem7krI3LKPkPxU6GJbIFwqpdhuTXQK YaYrxis+esM9llMiUl89nZ2+OxWuRxhOzBMRrLyayu5b2V3ho+/3b/A== X-Gm-Gg: AZFdTZcuLw/6Fhf517yBQBLhd7SS48qSRePYPBBwb8nX215UOg/Z986sG8/6RJWgh1q f7WTuNQE0o4czC3ipInqLlGeW2/UwkLcgEIDtZqQ5C87h8rjXbNz14EwqOQ3IgogF/yVjz+PbEr /XWGrfT/Bbg2kjUjCsfpnpU2+I9qHG2yBVeG7lk7VGCY+I2KFEQAxMz8OmJ79WsF0BvXTOK9La8 6vzG1mJoE/rj6FeeIoJhrUe3Am7koaIzcb6s/L5Dh8rufssKzH9RMJC+9YUKSHx+8NIDuDJNWPk QTMPUVJdUo50WKleTJp/sQY30AWNyoBHihBmddp0QH+TewIRQbZrYtiM2b/VcdqVYd2gztpOLqF v9mvf6x0v4zrPWjJTzWspLEYjEg== X-Received: by 2002:a17:906:3b54:b0:c50:4b7a:de71 with SMTP id a640c23a62f3a-c513a878fe0mr1163885766b.28.1795587168540; Tue, 24 Nov 2026 22:12:48 -0800 (PST) X-Received: by 2002:a17:906:3b54:b0:c50:4b7a:de71 with SMTP id a640c23a62f3a-c513a878fe0mr1163885166b.28.1795587168069; Tue, 24 Nov 2026 22:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795587168; cv=none; d=google.com; s=arc-20260327; b=lVGGHb2MneTOLFrtuplAxi5x/wyniV0mxZw7iRTpPohmxFt9wOjjqys0AyCxdm/ei+ Jl7kJpGvMyY3GjHSDFaf4mE5oenTzcTZXejoy26unFhqGvnPXW/6CPK+3KpEuAdTjwV2 BgkwVcgRqEntqLdATlrhP3Htg5GHV6eVZCtQDHBCEh96euZyny5lGb63JxnieVCmz1l4 H/RVKzHOBhWqo/ijw3YOpVw9yksetss9oNtIpyRGrCIfOFXpLkXhPp1eMIEF0OPm+8q8 vh9vI9XwnFdoQzlrfLn4GydINEGWUmBlCnO+hIopew/R/e7jx1r6jeQBnjoyfy/WqeeK Be2g== 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=kty8SoZ979vNCYLTeoUGcUZAryD+Y+6TgwpWKrf/cnU=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=pxSpsrj7xXqwOd894GxQK6ixRbCP/zXEZ481fgoEI1oSb2kINQuV3xKL7+Nb0mhXju ViedGuKB5e16+btRGwN/O7Jwm7S9qWKayy+nXsnI/ll9HhyrALcO22vJv6Cvh5A9zRfN KbbXLMShbN8TtzAci9u/DRMaa+rI0BIsTtql1LgNo7997xopxWoZ2D6zjjdg1taRm0av t9cB0Z7zVuNxMAG2lki4Fv3sn0+Jo02zcHgmDxgm7/gBwIHV/cuEAS4fmPkgWg1Ury08 w34UTjRGA+9G2DXMfuz2jH6pwgO17tx8Q9JVsYFGkaCiKjGx0mbl8QLisuwTpMikwpwt N/4Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QB6SlhbC; 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-c513b0d9860si1074970566b.387.2026.11.24.22.12.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 22:12:48 -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=QB6SlhbC; 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=kty8SoZ979vNCYLTeoUGcUZAryD+Y+6TgwpWKrf/cnU=; b=QB6SlhbCtgRm mSVT9HtD1Zl0sF402d+GSjQNRCROVUtt9aHyaSmTSOB8ZOz1cI9Ss4tydEORulwwprvP6JmjT0A+H oO/eB7c3a9qHAKovOXOZIwljCpzlU1javMuGfqUH6QVG/ERbQ/y6+n9uHN9cnZIBdlLhLBFxuS5me ldDmVnNwVc96umRQtaTTN7eMvsVSZH35x8H+pOfoWwZ2kqixkcpKQIMWfcfyMCSxqzcNSaV8ALHNu yGuhe/2qU2vKV1epfejDayjc+TOk8ab9Wr02AzZgTJIG8iyi1yKJUmMSpRhwGeR0CZwprkiFrmtJA FLRc+ah6kQlFOyBhaUyzpg==; 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 1xW6E7-006jhw-1i; Wed, 25 Nov 2026 07:11:42 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Wed, 25 Nov 2026 08:03:56 +0200 Message-ID: <20261125061124.1995383-15-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125061124.1995383-1-eva.kurchatova@virtuozzo.com> References: <20261125061124.1995383-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 14/18] objtool/klp: Reject changed .rodata objects 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 Since "objtool/klp: Fix pointer comparisons for rodata objects", a named .rodata object is correlated, and the patched code references the original through a klp reloc. A change to the object, such as a new row of a static const table, is then lost without notice; so is a reference to another function's same-named local table, which correlation by name in order binds when the patch adds one earlier in the file. Fail klp diff when a correlated .rodata object differs in length, bytes or relocations, as mainline does since 6016dd33a10a ("objtool/klp: Rewrite symbol correlation algorithm"), which is too large to take here. Relocations are compared by target: strings by contents, correlated symbols by twin and offset, uncorrelated ones such as __func__ by name and bytes, anything else by section and offset. https://virtuozzo.atlassian.net/browse/VSTOR-128510 Feature: klp-build support Signed-off-by: Eva Kurchatova --- tools/objtool/klp-diff.c | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 2f1cedf9632b..177ec61d7d19 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -443,6 +443,119 @@ static int correlate_symbols(struct elfs *e) return 0; } +/* The symbol a reloc points into and the offset in it, NULL if anonymous */ +static struct symbol *reloc_target(struct reloc *reloc, s64 *offset) +{ + struct symbol *sym = reloc->sym; + + *offset = arch_adjusted_addend(reloc); + if (!is_sec_sym(sym)) + return sym; + + sym = find_symbol_containing_inclusive(sym->sec, *offset); + if (sym) + *offset -= sym->offset; + return sym; +} + +static const void *sym_data(struct symbol *sym) +{ + if (!sym->sec->data || !sym->sec->data->d_buf) + return NULL; + + return sym->sec->data->d_buf + sym->offset; +} + +static const char *reloc_string(struct reloc *reloc) +{ + struct symbol *sym = reloc->sym; + + return sym->sec->data->d_buf + sym->offset + arch_adjusted_addend(reloc); +} + +static bool reloc_changed(struct reloc *orig, struct reloc *patched) +{ + struct symbol *orig_sym, *patched_sym; + s64 orig_off, patched_off; + + if (reloc_type(orig) != reloc_type(patched)) + return true; + + /* Strings move inside their merged section: compare the contents */ + if (is_string_sec(orig->sym->sec) || is_string_sec(patched->sym->sec)) + return !is_string_sec(orig->sym->sec) || + !is_string_sec(patched->sym->sec) || + strcmp(reloc_string(orig), reloc_string(patched)); + + orig_sym = reloc_target(orig, &orig_off); + patched_sym = reloc_target(patched, &patched_off); + + if (!orig_sym || !patched_sym) + return orig_sym != patched_sym || + strcmp(orig->sym->sec->name, patched->sym->sec->name) || + arch_adjusted_addend(orig) != arch_adjusted_addend(patched); + + if (orig_off != patched_off) + return true; + + if (orig_sym->twin || patched_sym->twin) + return orig_sym->twin != patched_sym; + + /* Uncorrelated, e.g. __func__: the original stays referenced too */ + return strcmp(orig_sym->demangled_name, patched_sym->demangled_name) || + orig_sym->len != patched_sym->len || + (sym_data(orig_sym) && sym_data(patched_sym) && + memcmp(sym_data(orig_sym), sym_data(patched_sym), orig_sym->len)); +} + +static bool object_changed(struct elfs *e, struct symbol *orig, struct symbol *patched) +{ + struct reloc *orig_reloc, *patched_reloc; + + /* A twin outside .rodata (no longer const) loses the change too */ + if (!is_rodata_sec(patched->sec) || orig->len != patched->len || + (orig->len && memcmp(sym_data(orig), sym_data(patched), orig->len))) + return true; + + patched_reloc = find_reloc_by_dest_range(e->patched, patched->sec, + patched->offset, patched->len); + sym_for_each_reloc(e->orig, orig, orig_reloc) { + if (!patched_reloc || + reloc_offset(patched_reloc) >= patched->offset + patched->len || + reloc_offset(orig_reloc) - orig->offset != + reloc_offset(patched_reloc) - patched->offset || + reloc_changed(orig_reloc, patched_reloc)) + return true; + + patched_reloc = rsec_next_reloc(patched->sec->rsec, patched_reloc); + } + + return patched_reloc && + reloc_offset(patched_reloc) < patched->offset + patched->len; +} + +/* + * The patched code references a correlated .rodata object through a klp + * reloc to the original, so a change to the object would be lost. + */ +static int check_changed_rodata(struct elfs *e) +{ + struct symbol *orig; + int ret = 0; + + for_each_sym(e->orig, orig) { + if (!is_object_sym(orig) || !is_rodata_sec(orig->sec) || !orig->twin) + continue; + + if (object_changed(e, orig, orig->twin)) { + ERROR("changed data: %s", orig->name); + ret = -1; + } + } + + return ret; +} + /* "sympos" is used by livepatch to disambiguate duplicate symbol names */ static unsigned long find_sympos(struct elf *elf, struct symbol *sym) { @@ -1714,6 +1827,9 @@ int cmd_klp_diff(int argc, const char **argv) if (correlate_symbols(&e)) return -1; + if (check_changed_rodata(&e)) + return -1; + if (mark_changed_functions(&e)) return 0; -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel