[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/4] xen: resolve MISRA C Rule 11.8 in xen_build_id_check()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Tue, 17 Nov 2026 21:48:14 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LErmF/bJlLM5D7v38QUNMSPLvquYKqgM6IzXspADTME=; b=I1gsYO+cZWtKpgJG2v531WfcxrH7Cb2RwNBeveFbayaIytO1z1sW86CiCkrfmssRnH7WYSH9Yo3LvLFCzk9qw1Fp5S6GrEokgt9bI3vlbHIiccyAHxAJZBJBiOrTFwJiF11kOD6Pkd7sNVWmxHIpJDbTBBRHFm/MaA7aIZPNubJnjlBw6+DzB0aYx0mllIeEZ2eDz3ryl0kRSaGmTxr6OrlxefLqGh6iAXJhmUKi/ulfrNrtf9cC/25ZYig4o0XLt55kgSJNRJN/dNJ0CMWIBHudCGNbBJ6cCWZIzjjFYuGcuaKOdBcjWy3+hNaXC3qxUyPhPcnAg85qLGKVpjVOoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f1pNf368pnI5ZhLgkQmMtS0tIl17muyZwqTtgNuzOiEg05GXb+BtKk2EdxWIQnj+a+J9sXA+PCqoR0edyL1HKokZBPhhRiAqQa1iEpvCwXHEgNHv1THjRUq6cmCH7FiMs4sKrLFp/Q02F/NtS94U/GPdkfuJNVunJXN/2CzxhByyiuTSJ/c4zsM1QMq1gAB3Bek6aj6LvbcP9F26hR/IqlI1A1TcG5TLOAqQLvq8kBw9KZP7NIXd51oO3NwnMjMPGLMJZQ83yyB0+BYC0q0wVl/Fvvnz6qJHO3uUN/lb98o2cT7PqiPfKBuq91Ubryojk5mwGHrrKAytVB7d+GXDyA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 17 Nov 2026 19:48:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 11/3/26 13:16, Jan Beulich wrote:
On 03.11.2026 11:29, Dmytro Prokopchuk1 wrote:
ELFNOTE_NAME() unconditionally casts its argument to 'char *', and
ELFNOTE_DESC() is built on top of it. xen_build_id_check() passes a
'const Elf_Note *' to both of them, so the const qualifier is cast away,
which is a violation of MISRA C Rule 11.8.

Introduce ELFNOTE_NAME_CONST() and ELFNOTE_DESC_CONST() for read-only
access to the note, and use them in xen_build_id_check().

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>

It again would have been nice if it was mentioned that this is an alternative
proposal to an earlier posted patch, [1]. Personally here I prefer my variant
(with the adjustment as per review feedback, pending a v2 submission).

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2026-09/msg00045.html


Sorry for not referencing [1].
I will drop this patch and wait for your v2.

--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -133,13 +133,13 @@ int xen_build_id_check(const Elf_Note *n, unsigned int 
n_sz,
          return -EINVAL;
/* Sanity check, name should be "GNU" for ld-generated build-id. */
-    if ( strncmp(ELFNOTE_NAME(n), "GNU", n->namesz) != 0 )
+    if ( strncmp(ELFNOTE_NAME_CONST(n), "GNU", n->namesz) != 0 )
          return -ENODATA;
if ( len )
          *len = n->descsz;
      if ( p )
-        *p = ELFNOTE_DESC(n);
+        *p = ELFNOTE_DESC_CONST(n);
return 0;
  }
diff --git a/xen/include/xen/elf.h b/xen/include/xen/elf.h
index 4199b4d6e6..3337b8cabe 100644
--- a/xen/include/xen/elf.h
+++ b/xen/include/xen/elf.h
@@ -34,4 +34,8 @@
  #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + ELFNOTE_ALIGN((_n_)->namesz))
  #define ELFNOTE_NEXT(_n_) ((Elf_Note *)(ELFNOTE_DESC(_n_) + 
ELFNOTE_ALIGN((_n_)->descsz)))
+#define ELFNOTE_NAME_CONST(_n_) ((const char *)(_n_) + sizeof(*(_n_)))
+#define ELFNOTE_DESC_CONST(_n_) \
+    (ELFNOTE_NAME_CONST(_n_) + ELFNOTE_ALIGN((_n_)->namesz))
+
  #endif /* __XEN_ELF_H__ */


BR, Dmytro.




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.