Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932860AbbDUPgY (ORCPT ); Tue, 21 Apr 2015 11:36:24 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58675 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932744AbbDUPgR (ORCPT ); Tue, 21 Apr 2015 11:36:17 -0400 Date: Tue, 21 Apr 2015 17:36:13 +0200 From: Jean Delvare To: Ivan Khoronzhuk Cc: linux-kernel@vger.kernel.org, matt.fleming@intel.com, ard.biesheuvel@linaro.org, grant.likely@linaro.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, mikew@google.com, dmidecode-devel@nongnu.org, leif.lindholm@linaro.org, msalter@redhat.com, roy.franz@linaro.org Subject: Re: [Patch v2 2/3] firmware: dmi_scan: add SBMIOS entry and DMI tables Message-ID: <20150421173613.6601da15@endymion.delvare> In-Reply-To: <1429525187-3376-3-git-send-email-ivan.khoronzhuk@globallogic.com> References: <1429525187-3376-1-git-send-email-ivan.khoronzhuk@globallogic.com> <1429525187-3376-3-git-send-email-ivan.khoronzhuk@globallogic.com> Organization: SUSE Linux X-Mailer: Claws Mail 3.10.1 (GTK+ 2.24.23; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1720 Lines: 41 Hi again Ivan, On Mon, 20 Apr 2015 13:19:46 +0300, Ivan Khoronzhuk wrote: > + bin_attr_DMI.size = dmi_len; > + bin_attr_DMI.private = dmi_table; > + ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI); > + if (!ret) > + return 0; I just found that more work is needed here for the SMBIOS v3 entry point case. These entry points do not specify the exact length of the table, but only its maximum. The real world sample I have access to indeed specifies a maximum length of 6419 bytes, but the actual table only spans over 2373 bytes. It is properly terminated with a type 127 DMI structure, so the kernel table parser ignores the garbage after it. The garbage is however exported to user-space above. I taught dmidecode to ignore the garbage, but there are two problem left here. First problem is a waste of memory. Minor issue I suppose, who cares about a few kilobytes these days. Second problem is a security problem. We are leaking the contents of physical memory to user-space. In my case it's filled with 0xffs so no big deal. But what if actual data happens to be stored there? It definitely shouldn't go to user-space. So dmi_len needs to be trimmed to the actual table size before the attribute above is created. I have an idea how this could be implemented easily, let me give it a try. Maybe we should trim the length for previous implementations, too. There is no reason to walk past a type 127 structure anyway, ever. -- Jean Delvare SUSE L3 Support -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/