From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45C7A29AB05 for ; Mon, 22 Dec 2025 17:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766425925; cv=none; b=UV4PglWdb5LWA4QmvBTQKxayYaK1cf040W+cIesCw835pUsI3QtJTHwFVoTydrxOE1ffEYSvZ4EdO+RZ/pNkoVlGKE+l/eN7sEseyUuXIwg35Uvn7Xwvf9GKmHTYPnzLr6T4v0ZnKsuNyBhQR2aR0l9+sjjLljSygfIEQmtjw9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766425925; c=relaxed/simple; bh=oT2xAnAnuKhdJbO8UtCJzcPFpGGUX/6FnMG6r13BB4w=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E1UtvBQ+O9inBaRDQ5q6zYHq2ceSjEXtJWD9oxZaQy4B8+eb5dYJm3jRGnTuiLUbQ27bi9VMg4VgGQMt85N2HRG7lGYRJDf3spiKj2sI50ULZ0n3pI6hJFMsbWqkHYiRVXsdUv0G0yj+cHvYRLnbMsBn8yp8ISAtIbf2arl6X0I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=vw8paxq5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=K8EF5ANd; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=T/PLvh9Z; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=NmsUjmu7; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="vw8paxq5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="K8EF5ANd"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="T/PLvh9Z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="NmsUjmu7" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 13E57336B6; Mon, 22 Dec 2025 17:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1766425921; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l87woLrdOhwUuCPudgmFjgxewGo43IVNn2tez77pQgU=; b=vw8paxq5IrF6UAimAV4wM1zoKvRM0tYbCNUXn8XmWLdIWdJSdKt4hsf15Rx9yndyFrRxNH lHrcPMQvSue/zKRKFsMbcVp9ZLbs6pes2z18QDlivkz79CdSWTshiWECz1yyz1MDB9qxYN aF8nMAatpyc2ycrTl25mhgYWlZGZp4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1766425921; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l87woLrdOhwUuCPudgmFjgxewGo43IVNn2tez77pQgU=; b=K8EF5ANdD5mGPalLzfeiKOvwVFKPaK4NQwL8Nw3uDU2VQwLXfMPPIPd/rxzjrDsJDW1a6g AaIsGCE+8A6DJYBA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="T/PLvh9Z"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NmsUjmu7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1766425920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l87woLrdOhwUuCPudgmFjgxewGo43IVNn2tez77pQgU=; b=T/PLvh9ZeUfWpZSHt7p4APG2sJQmQM1efRzNcZQSDRTVgsqVcxuaykxKuQsWCzZlvpbGC2 awA5iEne35+joJrxWDeVlgvtq48wPFmJMvP+TkRzn19TSnlKdxNNGSY35KChjCq0jxRmcr v90RQPX2rQ6/qYz41JQxRfmoGh3uyV0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1766425920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l87woLrdOhwUuCPudgmFjgxewGo43IVNn2tez77pQgU=; b=NmsUjmu7Uq5mkYsyzBhjAQAhCB833QkqTRVX7/MQM7peCM3nwCI0tJU88G4GL4AhQHfpci f1GcuNzirOVJAwBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A9A971364B; Mon, 22 Dec 2025 17:51:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id tCtbJz+FSWkhJwAAD6G6ig (envelope-from ); Mon, 22 Dec 2025 17:51:59 +0000 Date: Mon, 22 Dec 2025 18:51:58 +0100 From: Jean Delvare To: "Mario Limonciello (AMD)" Cc: Yazen Ghannam , x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/7] firmware: dmi: Read additional information when decoding DMI table Message-ID: <20251222185158.5386b3e7@endymion> In-Reply-To: <20251216123354.9219-4-superm1@kernel.org> References: <20251216123354.9219-1-superm1@kernel.org> <20251216123354.9219-4-superm1@kernel.org> Organization: SUSE Linux X-Mailer: Claws Mail 4.2.0 (GTK 3.24.43; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; HAS_ORG_HEADER(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spam-Level: X-Rspamd-Queue-Id: 13E57336B6 X-Spam-Flag: NO X-Spam-Score: -4.01 Hi Mario, On Tue, 16 Dec 2025 06:33:50 -0600, Mario Limonciello (AMD) wrote: > Type 40 entries (Additional information) are summarized in section > 7.41 as part of the SMBIOS specification. Save these entries when > decoding the DMI tables. > > Signed-off-by: Mario Limonciello (AMD) > --- > v2: > * Drop some unneeded variables (LKP robot) > * Allow any length strings, not just 5 and longer > --- > drivers/firmware/dmi_scan.c | 38 +++++++++++++++++++++++++++++++++++++ > include/linux/dmi.h | 7 +++++++ > 2 files changed, 45 insertions(+) > > diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c > index 80aded4c778bc..ec84fe3935c1e 100644 > --- a/drivers/firmware/dmi_scan.c > +++ b/drivers/firmware/dmi_scan.c > @@ -393,6 +393,40 @@ static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus, > list_add(&dev->dev.list, &dmi_devices); > } > > +static void __init dmi_save_additional(const struct dmi_additional_info *info) > +{ > + const u8 *data; > + int i; > + > + if (!info || info->header.length < 5 + info->count * 5) Evaluating the second condition will access info->count, which is not guaranteed to exist if info->header.length < 5. Of course if the DMI table is compliant, it will be fine, but you can't rely on firmware-provided data being sane. Second problem is that you seem to assume that every entry has size 5 bytes. The SMBIOS specification says that the minimum size is 6 bytes, and the actual size is stored in the first byte of each entry. So you can't validate the total length upfront. You need to check as you walk the table that the next entry would fit in the DMI record. (The actual length will be 6 bytes if adding a value for an 8-bit field, which is certainly the most frequent use case. But if adding a value for a 16-bit field for example, then the entry would be 7 byte long.) > + return; > + > + data = info->entries; > + > + for (i = 0; i < info->count; i++) { > + u8 string_num = data[i * 5 + 4]; > + const char *string_ptr; > + char *value; > + int len; > + > + string_ptr = dmi_string_nosave(&info->header, string_num); > + if (!string_ptr || !*string_ptr) > + continue; > + > + len = strlen(string_ptr); > + if (len == 0) > + continue; > + > + value = dmi_alloc(len + 1); > + if (!value) > + continue; > + > + strscpy(value, string_ptr, len + 1); Not sure why you allocate memory for the string, considering that dmi_save_one_device() below does it too? > + > + dmi_save_one_device(DMI_DEV_TYPE_ADDITIONAL, value); > + } > +} I'm not thrilled by the interface this offers. You end up arbitrarily saving only one piece of information from the record (the free-form string). You omit the reference handle (which isn't super-useful per se, but could be used to find out the base DMI type, which would be useful), nor the field offset within that DMI type, nor the new value associated with that field. This might be OK with your immediate use case, but lacks flexibility if anyone else ever needs data from such a record. Even for your use case, this seems pretty fragile. You end up considering that any string starting with "AGESA" in a type 40 DMI record is what you are looking for. While you don't have any guarantee that the record in question relates to the CPU in general nor to one specific type 4 record field. This could result in false positives. > + > static void __init dmi_save_extended_devices(const struct dmi_header *dm) > { > const char *name; > @@ -526,8 +560,12 @@ static void __init dmi_decode(const struct dmi_header *dm, void *dummy) > case DMI_ENTRY_IPMI_DEV: > dmi_save_ipmi_device(dm); > break; > + case DMI_ENTRY_ADDITIONAL: > + dmi_save_additional((const struct dmi_additional_info *)dm); > + break; > case DMI_ENTRY_ONBOARD_DEV_EXT: > dmi_save_extended_devices(dm); > + break; > } > } > > diff --git a/include/linux/dmi.h b/include/linux/dmi.h > index a809b5095c259..3fc3d334b321d 100644 > --- a/include/linux/dmi.h > +++ b/include/linux/dmi.h > @@ -24,6 +24,7 @@ enum dmi_device_type { > DMI_DEV_TYPE_OEM_STRING = -2, > DMI_DEV_TYPE_DEV_ONBOARD = -3, > DMI_DEV_TYPE_DEV_SLOT = -4, > + DMI_DEV_TYPE_ADDITIONAL = -5, > }; > > enum dmi_entry_type { > @@ -87,6 +88,12 @@ struct dmi_device { > void *device_data; /* Type specific data */ > }; > > +struct dmi_additional_info { > + struct dmi_header header; > + u8 count; > + u8 entries[]; > +} __packed; > + > #ifdef CONFIG_DMI > > struct dmi_dev_onboard { -- Jean Delvare SUSE L3 Support