From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757870AbaGWKLM (ORCPT ); Wed, 23 Jul 2014 06:11:12 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35325 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757533AbaGWKLI (ORCPT ); Wed, 23 Jul 2014 06:11:08 -0400 Date: Wed, 23 Jul 2014 12:11:06 +0200 Message-ID: From: Takashi Iwai To: Kees Cook Cc: LKML , James Morris , Greg Kroah-Hartman , Ming Lei , linux-security-module Subject: Re: [PATCH v2 2/2] firmware_class: perform new LSM checks In-Reply-To: References: <1405969601-4234-1-git-send-email-keescook@chromium.org> <1405969601-4234-3-git-send-email-keescook@chromium.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At Tue, 22 Jul 2014 10:39:00 -0700, Kees Cook wrote: > > On Mon, Jul 21, 2014 at 11:55 PM, Takashi Iwai wrote: > > At Mon, 21 Jul 2014 12:06:41 -0700, > > Kees Cook wrote: > >> > >> This attaches LSM hooks to the existing firmware loading interfaces: > >> filesystem-found firmware and demand-loaded blobs. > >> > >> Signed-off-by: Kees Cook > >> Acked-by: Greg Kroah-Hartman > >> --- > >> drivers/base/firmware_class.c | 16 ++++++++++++++-- > >> 1 file changed, 14 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c > >> index d276e33880be..7399bab71ced 100644 > >> --- a/drivers/base/firmware_class.c > >> +++ b/drivers/base/firmware_class.c > >> @@ -28,6 +28,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> > >> #include > >> > >> @@ -308,12 +309,17 @@ static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf) > >> if (rc != size) { > >> if (rc > 0) > >> rc = -EIO; > >> - vfree(buf); > >> - return rc; > >> + goto fail; > >> } > >> + rc = security_kernel_fw_from_file(file, buf, size); > >> + if (rc) > >> + goto fail; > >> fw_buf->data = buf; > >> fw_buf->size = size; > >> return 0; > >> +fail: > >> + vfree(buf); > >> + return rc; > >> } > >> > >> static int fw_get_filesystem_firmware(struct device *device, > >> @@ -640,6 +646,12 @@ static ssize_t firmware_loading_store(struct device *dev, > >> break; > >> case 0: > >> if (test_bit(FW_STATUS_LOADING, &fw_buf->status)) { > >> + if (security_kernel_fw_from_file(NULL, fw_buf->data, > >> + fw_buf->size)) { > >> + fw_load_abort(fw_priv); > >> + break; > >> + } > >> set_bit(FW_STATUS_DONE, &fw_buf->status); > >> clear_bit(FW_STATUS_LOADING, &fw_buf->status); > > > > security_kernel_fw_from_file() should be called after > > fw_map_pages_buf() call (that is found after these lines). > > Otherwise fw_buf->buf won't contain a valid buffer pointer. > > Ah! Good to know. I guess I was getting lucky in my testing. Is this a > race condition? This is the code path where direct f/w loading fails but the user-space helper feeds the data. Did you test that scenario? Takashi