Received: by 10.213.65.68 with SMTP id h4csp788821imn; Tue, 13 Mar 2018 23:17:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELuoEx78m1P4SUnR+NFs2j7sd7rqxUn6gxkBI+sFrfjARbOOz8XMgutPKs/8ALmk6hU5aPgA X-Received: by 10.98.15.72 with SMTP id x69mr3162366pfi.16.1521008279345; Tue, 13 Mar 2018 23:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521008279; cv=none; d=google.com; s=arc-20160816; b=sn08h8wW9UMpbPeDcD3QmVU9f9bDDctkWmu9SWsJpHYYSKMRUFQNPvPQIOLTabTu0A OCjfku18jTQwSt6cRRPU6lj6DEa/M+IDz56ThJ04wfJAMNLbd4pJ1Tq0v83r06CMsJoM PJklrmjqakCGB60IT6chyblnlzz4ONkl/ogi9twfuvaCTkgMp1zWCDA1zA1nxgQ6h14P yT773jF84sjCXMYII5EWL5EslVu6dHVS+qLEkiHNkg6vZtp+cpr08l2sF1DkKdVkm1x2 QSr5on/XTu9SgO2+a84ZTFfT9MzeUl2Xt6UQTcqPyYmcrwi81acUI3lllqP2z1bSbfSC ozHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:references:in-reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/nNB1Kjx2Kmw3uU9LfoY2P4EZY5pEAyzI3/2dBuvYLw=; b=g5tzGVdj4mPEADlLJ7O7RiSmn2eRsTay+QOk12Q9fAf9dsA0y8n2SgQop0WSmhQKSJ n9YpbwINIrDrKPrgYOHWnvgv+w51qY1pZJYxq+zr0JvVwv9oDnRF6EUvefRMuOyG5Sgt 2U4WPX16FsnGbfvfjWjaAoroky78IZvJp4Yw85CS//8dx3QWSskKyfB3XHEQHIDfI3h1 pn+Xcm30b0Axc7lnvDtl8vam1W5vdte0Z+LQrNbyUDw1YNY6HkPg8bbWW1zSJ610Pnxr a+HcTl1H4obY+nU95ZDElLBdmZfkMvuoSBpGZpmAcrmfymoZlit4we93diYTzTRL0d21 l96w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11-v6si1444523plj.701.2018.03.13.23.17.45; Tue, 13 Mar 2018 23:17:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933425AbeCNGQo (ORCPT + 99 others); Wed, 14 Mar 2018 02:16:44 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:41416 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933184AbeCNGQm (ORCPT ); Wed, 14 Mar 2018 02:16:42 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de (mx-rz-2.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx-rz-2.rrze.uni-erlangen.de (Postfix) with ESMTPS id 401M1h4J8qzPjyG; Wed, 14 Mar 2018 07:16:40 +0100 (CET) Authentication-Results: mx-rz-2.rrze.uni-erlangen.de; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Quarantine-ID: X-Virus-Scanned: amavisd-new at boeck1.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Header field occurs more than once: "References" occurs 3 times X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3e7:2500:bfbd:dba3:49d6:7204 Received: from fau.de (p200300D503E72500BFBDDBA349D67204.dip0.t-ipconnect.de [IPv6:2003:d5:3e7:2500:bfbd:dba3:49d6:7204]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX1868yDfTbopDE9pRgsoxqpox1hEEPHXdQQ=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 401M1d214zzPkDS; Wed, 14 Mar 2018 07:16:37 +0100 (CET) From: Jonas Rabenstein To: Jonas Rabenstein , Scott Bauer , Jonathan Derrick , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 8.4/8.4] block: sed-opal: check size of shadow mbr Date: Wed, 14 Mar 2018 07:15:45 +0100 Message-Id: <33f9dab3352e95588a7e4a4680beb068db285b7f.1521006596.git.jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: <20180313154416.sgptuw7jcn7l76vn@sbauer-Z170X-UD5> References: <20180313154416.sgptuw7jcn7l76vn@sbauer-Z170X-UD5> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check whether the shadow mbr does fit in the provided space on the target. Also a proper firmware should handle this case and return an error we may prevent problem with crappy firmwares. Signed-off-by: Jonas Rabenstein --- block/sed-opal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/sed-opal.c b/block/sed-opal.c index 4d93a6097ec0..8a08ae91bc25 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -1544,6 +1544,20 @@ static int write_shadow_mbr(struct opal_dev *dev, void *data) u64 len; int err = 0; + /* do we fit in the available shadow mbr space? */ + err = generic_get_table_info(dev, OPAL_MBR, OPAL_TABLE_ROWS); + if (err) { + pr_debug("MBR: could not get shadow size\n"); + return err; + } + + len = response_get_u64(&dev->parsed, 4); + if (shadow->offset + shadow->size > len) { + pr_debug("MBR: does not fit in shadow (%llu vs. %llu)\n", + shadow->offset + shadow->size, len); + return -ENOSPC; + } + /* FIXME: this is the maximum we can use for IO_BUFFER_LENGTH=2048. * Instead of having constant, it would be nice to compute the * actual value depending on IO_BUFFER_LENGTH -- 2.16.1