From patchwork Thu Oct 17 10:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1178439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 ozlabs.org (Postfix) with ESMTPS id 46v4YJ07Rkz9sPJ for ; Thu, 17 Oct 2019 21:05:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="dG0KNH2G"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46v4YH5MYvzDrGp for ; Thu, 17 Oct 2019 21:05:39 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="dG0KNH2G"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46v4Y84DSFzDrDg for ; Thu, 17 Oct 2019 21:05:29 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id E6BF842F14; Thu, 17 Oct 2019 10:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1571306723; x= 1573121124; bh=jKu7exXujQNyQGHqYA30kszx9oPt918RnvbplF7fc24=; b=d G0KNH2GO6+pK0OKUXQoAc4c/YN/oO6PEDMe/HDOOTh7tryzBZZ5hQZNaaa+aQDjE MexBEiWiL3vLDnq6OfUXvgu/6hooh6Y6kbjDTBu8JABVAF+qcu0qMFQvSBPjpJVR 4Wbzyfydc/+dJUGWAtcOE803WWIPuDO1VD/WvfaSRQ= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w2oEeMKJf5cy; Thu, 17 Oct 2019 13:05:23 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 9AB484122E; Thu, 17 Oct 2019 13:05:23 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 17 Oct 2019 13:05:22 +0300 Date: Thu, 17 Oct 2019 13:05:22 +0300 From: Maxim Polyakov To: Jeremy Kerr , , Maxim Polyakov Subject: [PATCH v3 1/5] discover/platform-powerpc: add missing mbox block selector Message-ID: <20191017100521.GA6611@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" According to IPMI Specification, in the IPMI response message with boot initiator mailbox information block, byte 4 should be used as the block selector (1). However, this parameter isn`t taken into account in the code and bytes 4-6 in the block 0 are defined as the IANA enterprise ID number. Thus, IANA contains an invalid value and doesn`t match the IBM ID. For this reason, the get_ipmi_boot_mailbox() procedure fails with error and the boot options from mailbox doesn`t apply. /var/log/petitboot/pb-discover.log: IANA number unrecognised: 0x00:0x02:0x00 This patch adds the missing block selector parameter. It has been tested on the YADRO Vesnin P8 Server with the Openbmc [1] page 398, IPMI Specification v2.0, Revision 1.1, October 1, 2013 Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 5d7cc59..6651e3f 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -440,7 +440,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, char *buf, uint8_t block) { size_t blocksize = 16; - uint8_t resp[3 + 16]; + uint8_t resp[3 + 1 + 16]; uint16_t resp_len; char *debug_buf; int rc; @@ -462,7 +462,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, } if (resp_len < sizeof(resp)) { - if (resp_len < 3) { + if (resp_len < 4) { pb_log("platform: unexpected length (%d) in " "boot options mailbox response\n", resp_len); @@ -474,7 +474,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return 0; } - blocksize = sizeof(resp) - 3; + blocksize = sizeof(resp) - 4; pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", block, blocksize); } @@ -502,7 +502,14 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return -1; } - memcpy(buf, &resp[3], blocksize); + /* check for block number */ + if (resp[3] != block) { + pb_debug("platform: returned boot mailbox block doesn't match " + "requested\n"); + return -1; + } + + memcpy(buf, &resp[4], blocksize); return blocksize; } From patchwork Thu Oct 17 10:05:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1178441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46v4Yc4MnXz9sPV for ; Thu, 17 Oct 2019 21:05:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="PKmqFUup"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46v4Yc2K1KzDqLT for ; Thu, 17 Oct 2019 21:05:56 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="PKmqFUup"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46v4YJ3SJSzDrH8 for ; Thu, 17 Oct 2019 21:05:40 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 9CF2B43130; Thu, 17 Oct 2019 10:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1571306736; x= 1573121137; bh=SiNKX4dmfEeeV1QHMWEXkGl6R03jl/SMGPc8JLQarGg=; b=P KmqFUupvwZMeSVRyz4j0VTiNS6gCWjoUdHKG69aqIXo1+PFIZh2vD69x9SzfiHhV V1OB2vG+VSWdBN1ti1nqXoXdAlu6ja+OWv9TbXAkA6MLelvrbqkoaY8BEWBRtg97 KpIpQm/w8regC/Xu9Zltwd52QJskSmZH4Dz8xWVe5A= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K3dDxV9Yi89n; Thu, 17 Oct 2019 13:05:36 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id A31EA4122E; Thu, 17 Oct 2019 13:05:36 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 17 Oct 2019 13:05:36 +0300 Date: Thu, 17 Oct 2019 13:05:36 +0300 From: Maxim Polyakov To: Jeremy Kerr , , Maxim Polyakov Subject: [PATCH v3 2/5] discover/platform-powerpc: limit mailbox response size Message-ID: <20191017100534.GA6670@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" The maximum size of the mailbox with Boot Initiator info is defined in the specification (1). The code should not extract data from the IPMI response message if its size exceeds the maximum limit from the specification. [1] page 398, IPMI Specification v2.0, Revision 1.1, October 1, 2013 Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 6651e3f..1e33bf1 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -461,24 +461,27 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return -1; } - if (resp_len < sizeof(resp)) { - if (resp_len < 4) { - pb_log("platform: unexpected length (%d) in " - "boot options mailbox response\n", - resp_len); - return -1; - } + if (resp_len > sizeof(resp)) { + pb_debug("platform: invalid mailbox response size!\n"); + return -1; + } - if (resp_len == 4) { - pb_debug_fn("block %hu empty\n", block); - return 0; - } + if (resp_len < 4) { + pb_log("platform: unexpected length (%d) in " + "boot options mailbox response\n", + resp_len); + return -1; + } - blocksize = sizeof(resp) - 4; - pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", - block, blocksize); + if (resp_len == 4) { + pb_debug_fn("block %hu empty\n", block); + return 0; } + blocksize = sizeof(resp) - 4; + pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", + block, blocksize); + debug_buf = format_buffer(platform, resp, resp_len); pb_debug_fn("IPMI bootdev mailbox block %hu:\n%s\n", block, debug_buf); talloc_free(debug_buf); From patchwork Thu Oct 17 10:05:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1178442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46v4Ym1Jd4z9sPF for ; Thu, 17 Oct 2019 21:06:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="FQH3Ul9r"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46v4Yl71XHzDqKX for ; Thu, 17 Oct 2019 21:06:03 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="FQH3Ul9r"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46v4YW62mFzDqS9 for ; Thu, 17 Oct 2019 21:05:51 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id CF99D43130; Thu, 17 Oct 2019 10:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1571306747; x= 1573121148; bh=yhvXsZ5OOwT2BXYkoaS4+rxznVRxfi2xEL+gGTM2TEo=; b=F QH3Ul9rUoIM9FltZREgCJDLZ6UCgk9sL1SyZof9wTS+DS9juvieKKr0bWxEUjPVz 5vfo206lNYmPlPdu3HXfdQQI4kjOK+yhPPlc2qQQ3S7FL13RjwmzbcIvmsGOxfAo xlUbQ5oVbmGYGih1kq1/OhM35PFm6n2nqdfbOPnTiI= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 97WMvSWagIHv; Thu, 17 Oct 2019 13:05:47 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id DDEE442F14; Thu, 17 Oct 2019 13:05:47 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 17 Oct 2019 13:05:47 +0300 Date: Thu, 17 Oct 2019 13:05:47 +0300 From: Maxim Polyakov To: Jeremy Kerr , , Maxim Polyakov Subject: [PATCH v3 3/5] discover/platform-powerpc: return the actual mailbox size Message-ID: <20191017100545.GA6683@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" get_ipmi_boot_mailbox_block() should return the actual size of the received IPMI mailbox data Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 1e33bf1..c874560 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -473,12 +473,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return -1; } - if (resp_len == 4) { - pb_debug_fn("block %hu empty\n", block); - return 0; - } - - blocksize = sizeof(resp) - 4; + blocksize = resp_len - 4; pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", block, blocksize); @@ -512,6 +507,12 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return -1; } + if (!blocksize) { + pb_debug_fn("block %hu empty\n", block); + return 0; + } + + memcpy(buf, &resp[4], blocksize); return blocksize; From patchwork Thu Oct 17 10:05:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1178443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46v4Yx2lvRz9sNx for ; Thu, 17 Oct 2019 21:06:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="Vse/0qt4"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46v4Yx1N6HzDqLT for ; Thu, 17 Oct 2019 21:06:13 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="Vse/0qt4"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46v4Yn0PnXzDqSs for ; Thu, 17 Oct 2019 21:06:05 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 3C9EE437F6; Thu, 17 Oct 2019 10:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1571306761; x= 1573121162; bh=cYsVkHQhgrz/IvWDK8dBuONLSmgIm3cEns7ojpEYNbw=; b=V se/0qt4VDF8r3RhpwTZ+dNg96x+I8hT6teW7fAhPCdEXYqK1wB5nPEo/faGbQcbZ y17vbh31TnNTFTZsvXsjal71EZOAsHxF/rJ/nxZpghF84FLyrFZovd/nbpaMrd/o nCS8H6outJF+DIoeRjmbho+mZBs2ym4mF07j+w5Jr0= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A2Gb3lOcjNsQ; Thu, 17 Oct 2019 13:06:01 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 7432843130; Thu, 17 Oct 2019 13:06:00 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 17 Oct 2019 13:06:00 +0300 Date: Thu, 17 Oct 2019 13:05:59 +0300 From: Maxim Polyakov To: Jeremy Kerr , , Maxim Polyakov Subject: [PATCH v3 4/5] discover/platform-powerpc: add mailbox message structure Message-ID: <20191017100558.GA6697@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Use structure for the IPMI response mailbox message instead of raw byte array. Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 86 ++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index c874560..533e21a 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -22,6 +22,29 @@ #include "ipmi.h" #include "dt.h" +#define CHASSIS_BOOT_MBOX_IANA_SZ 3 +#define CHASSIS_BOOT_MBOX_DATA_SZ 16 +#define CHASSIS_BOOT_MBOX_BLOCK0_DATA_SZ \ + (CHASSIS_BOOT_MBOX_DATA_SZ - CHASSIS_BOOT_MBOX_IANA_SZ) + +struct mbox_block0 { + uint8_t iana[CHASSIS_BOOT_MBOX_IANA_SZ]; + uint8_t data[CHASSIS_BOOT_MBOX_BLOCK0_DATA_SZ]; +} __attribute__((packed)); + +union mbox { + uint8_t data[CHASSIS_BOOT_MBOX_DATA_SZ]; + struct mbox_block0 b0; +}; + +struct ipmi_mbox_response { + uint8_t cc; + uint8_t param_version; + uint8_t param_valid; + uint8_t block_selector; + union mbox mbox; +} __attribute__((packed)); + static const char *partition = "common"; static const char *sysparams_dir = "/sys/firmware/opal/sysparams/"; static const char *devtree_dir = "/proc/device-tree/"; @@ -437,10 +460,10 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform, } static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, - char *buf, uint8_t block) + union mbox *mailbox, uint8_t block) { - size_t blocksize = 16; - uint8_t resp[3 + 1 + 16]; + size_t blocksize; + struct ipmi_mbox_response ipmi_mbox_resp = { .cc = 0xFF }; uint16_t resp_len; char *debug_buf; int rc; @@ -449,59 +472,61 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, block, /* set selector */ 0x00, /* no block selector */ }; + const size_t ipmi_header_len = + sizeof(struct ipmi_mbox_response) - sizeof(union mbox); - resp_len = sizeof(resp); + resp_len = sizeof(struct ipmi_mbox_response); rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS, IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS, req, sizeof(req), - resp, &resp_len, + (uint8_t*)&ipmi_mbox_resp, &resp_len, ipmi_timeout); if (rc) { pb_log("platform: error reading IPMI boot options\n"); return -1; } - if (resp_len > sizeof(resp)) { + if (resp_len > sizeof(struct ipmi_mbox_response)) { pb_debug("platform: invalid mailbox response size!\n"); return -1; } - if (resp_len < 4) { + if (resp_len < ipmi_header_len) { pb_log("platform: unexpected length (%d) in " "boot options mailbox response\n", resp_len); return -1; } - blocksize = resp_len - 4; + blocksize = resp_len - ipmi_header_len; pb_debug_fn("Mailbox block %hu returns only %zu bytes in block\n", block, blocksize); - debug_buf = format_buffer(platform, resp, resp_len); + debug_buf = format_buffer(platform, (uint8_t*)&ipmi_mbox_resp, resp_len); pb_debug_fn("IPMI bootdev mailbox block %hu:\n%s\n", block, debug_buf); talloc_free(debug_buf); - if (resp[0] != 0) { + if (ipmi_mbox_resp.cc != 0) { pb_log("platform: non-zero completion code %d from IPMI req\n", - resp[0]); + ipmi_mbox_resp.cc); return -1; } /* check for correct parameter version */ - if ((resp[1] & 0xf) != 0x1) { + if ((ipmi_mbox_resp.param_version & 0xf) != 0x1) { pb_log("platform: unexpected version (0x%x) in " - "boot mailbox response\n", resp[0]); + "boot mailbox response\n", ipmi_mbox_resp.param_version); return -1; } /* check for valid paramters */ - if (resp[2] & 0x80) { + if (ipmi_mbox_resp.param_valid & 0x80) { pb_debug("platform: boot mailbox parameters are invalid/locked\n"); return -1; } /* check for block number */ - if (resp[3] != block) { + if (ipmi_mbox_resp.block_selector != block) { pb_debug("platform: returned boot mailbox block doesn't match " "requested\n"); return -1; @@ -512,8 +537,7 @@ static int get_ipmi_boot_mailbox_block(struct platform_powerpc *platform, return 0; } - - memcpy(buf, &resp[4], blocksize); + memcpy(mailbox, &ipmi_mbox_resp.mbox, blocksize); return blocksize; } @@ -522,12 +546,10 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, char **buf) { char *mailbox_buffer, *prefix; - const size_t blocksize = 16; - char block_buffer[blocksize]; + union mbox mailbox; size_t mailbox_size; int content_size; uint8_t i; - int rc; mailbox_buffer = NULL; mailbox_size = 0; @@ -538,15 +560,15 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, * on higher numbers. */ for (i = 0; i < UCHAR_MAX; i++) { - rc = get_ipmi_boot_mailbox_block(platform, block_buffer, i); - if (rc < 3 && i == 0) { + int block_size = get_ipmi_boot_mailbox_block(platform, &mailbox, i); + if (block_size < CHASSIS_BOOT_MBOX_IANA_SZ && i == 0) { /* * Immediate failure, no blocks read or missing IANA * number. */ return -1; } - if (rc < 1) { + if (block_size < 1) { /* Error or no bytes read */ break; } @@ -557,25 +579,25 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, * Enterprise ID number. Check it matches the IBM * number, '2'. */ - if (block_buffer[0] != 0x02 || - block_buffer[1] != 0x00 || - block_buffer[2] != 0x00) { + if (mailbox.b0.iana[0] != 0x02 || + mailbox.b0.iana[1] != 0x00 || + mailbox.b0.iana[2] != 0x00) { pb_log_fn("IANA number unrecognised: 0x%x:0x%x:0x%x\n", - block_buffer[0], - block_buffer[1], - block_buffer[2]); + mailbox.b0.iana[0], + mailbox.b0.iana[1], + mailbox.b0.iana[2]); return -1; } } mailbox_buffer = talloc_realloc(platform, mailbox_buffer, - char, mailbox_size + rc); + char, mailbox_size + block_size); if (!mailbox_buffer) { pb_log_fn("Failed to allocate mailbox buffer\n"); return -1; } - memcpy(mailbox_buffer + mailbox_size, block_buffer, rc); - mailbox_size += rc; + memcpy(mailbox_buffer + mailbox_size, &mailbox.data, block_size); + mailbox_size += block_size; } if (i < 5) From patchwork Thu Oct 17 10:06:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Polyakov X-Patchwork-Id: 1178444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46v4Z80Kh4z9sPF for ; Thu, 17 Oct 2019 21:06:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="qX85PKMA"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46v4Z75vKZzDqj4 for ; Thu, 17 Oct 2019 21:06:23 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=yadro.com (client-ip=89.207.88.252; helo=mta-01.yadro.com; envelope-from=m.polyakov@yadro.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="qX85PKMA"; dkim-atps=neutral Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46v4Z13wd3zDqRp for ; Thu, 17 Oct 2019 21:06:17 +1100 (AEDT) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 8933242F14; Thu, 17 Oct 2019 10:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= user-agent:content-disposition:content-type:content-type :mime-version:message-id:subject:subject:from:from:date:date :received:received:received; s=mta-01; t=1571306772; x= 1573121173; bh=EMt6o+UxPMS/NDhmZV+KrX7qXrUJKMWXSzjV2ZoU/lQ=; b=q X85PKMACpaxo56FqrkITX1pt1gsYBeLp8Y2CCx9zr1xX2PEX7M2S1uvxrHqZr2iu +eZIzxIPRfCgLLoJyQKlZDCDZ/JdB2iBkIwJ2E0Fl/2sEpq8rDZhDZXpPLRq9Qyz 234haSVYD8P6/cMLZpt9g0D5qYGHCOGBIxMEtgnX3I= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ql8iwAcVwmbV; Thu, 17 Oct 2019 13:06:12 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8160D4122E; Thu, 17 Oct 2019 13:06:12 +0300 (MSK) Received: from localhost (172.17.15.1) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 17 Oct 2019 13:06:12 +0300 Date: Thu, 17 Oct 2019 13:06:12 +0300 From: Maxim Polyakov To: Jeremy Kerr , , Maxim Polyakov Subject: [PATCH v3 5/5] discover/platform-powerpc: don't copy IANA from mbox to buffer Message-ID: <20191017100610.GA6709@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [172.17.15.1] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This patch adds code that takes into account the size of the IANA identifier number in the mailbox and doesn't copy it into the data buffer. Signed-off-by: Maxim Polyakov --- discover/platform-powerpc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 533e21a..8932dee 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -560,6 +560,7 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, * on higher numbers. */ for (i = 0; i < UCHAR_MAX; i++) { + uint8_t *boot_opt_data; int block_size = get_ipmi_boot_mailbox_block(platform, &mailbox, i); if (block_size < CHASSIS_BOOT_MBOX_IANA_SZ && i == 0) { /* @@ -576,9 +577,12 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, if (i == 0) { /* * The first three bytes of block zero are an IANA - * Enterprise ID number. Check it matches the IBM - * number, '2'. + * Enterprise ID number */ + block_size -= CHASSIS_BOOT_MBOX_IANA_SZ; + boot_opt_data = &mailbox.b0.data; + + /* Check IANA matches the IBM number, '2' */ if (mailbox.b0.iana[0] != 0x02 || mailbox.b0.iana[1] != 0x00 || mailbox.b0.iana[2] != 0x00) { @@ -588,6 +592,8 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, mailbox.b0.iana[2]); return -1; } + } else { + boot_opt_data = &mailbox.data; } mailbox_buffer = talloc_realloc(platform, mailbox_buffer, @@ -596,7 +602,7 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, pb_log_fn("Failed to allocate mailbox buffer\n"); return -1; } - memcpy(mailbox_buffer + mailbox_size, &mailbox.data, block_size); + memcpy(mailbox_buffer + mailbox_size, boot_opt_data, block_size); mailbox_size += block_size; } @@ -607,10 +613,10 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, else pb_debug_fn("%hu blocks read (%zu bytes)\n", i, mailbox_size); - if (mailbox_size < 3 + strlen("petitboot,bootdevs=")) + if (mailbox_size < strlen("petitboot,bootdevs=")) return -1; - prefix = talloc_strndup(mailbox_buffer, mailbox_buffer + 3, + prefix = talloc_strndup(mailbox_buffer, mailbox_buffer, strlen("petitboot,bootdevs=")); if (!prefix) { pb_log_fn("Couldn't check prefix\n"); @@ -628,9 +634,9 @@ static int get_ipmi_boot_mailbox(struct platform_powerpc *platform, } /* Don't include IANA number in buffer */ - content_size = mailbox_size - 3 - strlen("petitboot,bootdevs="); + content_size = mailbox_size - strlen("petitboot,bootdevs="); *buf = talloc_memdup(platform, - mailbox_buffer + 3 + strlen("petitboot,bootdevs="), + mailbox_buffer + strlen("petitboot,bootdevs="), content_size + 1); (*buf)[content_size] = '\0';