Received: by 10.213.65.68 with SMTP id h4csp1730844imn; Mon, 19 Mar 2018 11:40:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELsEtC0IcZw/uIm5LX9NYnjARKAcWUrRefPmBzZ0QPGzkTwp8LgxqdreST72Kjp1qTlaMUxN X-Received: by 10.99.170.5 with SMTP id e5mr9571791pgf.92.1521484853841; Mon, 19 Mar 2018 11:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484853; cv=none; d=google.com; s=arc-20160816; b=BAS6AYbMXHdzhGZp+9u6mgGYXce/BAgTwKcQWliNqZFydgdTQMrFv7ixO53XBgta8x MJ+oRfbLIXzkfmYIgzGOgj5EDGYJL5flRIDzV1DW6QAR5/ZuM6IGzsKPE7huUN9BvtHC Cyn1vohbLUwiFlt5yr8JzfzXv7XmO69f34elJiJT7RPB730EI5Lkdj93PEDCos3BeNks PvhUUvm6sDF0Ho5UUfcPp8+9TSTie0tQFX/Y2ibHY83FE6X0kZgAa2zHzIC+cxela9Lh Vd1eOBNM3qnZTlWasUyqLH5Uwm3UMw5FF8ymT1zc8hZNg/NLbmw6BVifs0el+6XIaxR8 Pr2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qSSufMnZe6pmWycUu6H+BBdPB9b+iVQMryTOStJPxVk=; b=wCllLPOQNvZ9HDShN9q6SuPmS7noW5sYPgeOxPdIrFv+cY1HFZxKW+NZ81Z3ueNfYb s8dlDpXbiio3bLOM5CmfO2ds1BDVCvvuTMaykrtQQUg8OMQ8iv2IyD3gkJ5CvL2oECZY 9BaZ2ZuQZYbloP7HWv+Fdw6kQTbzjEaG+wsVH71H3Ap+p1Tx61mN7RRkwpRFexcTlE9O LPVGUiesMGNkfsKPUM2GVNyEGjr7Ef6ruQ5yHfds1ggf/bD0P3U7+Wq3NSrdD0VrfZeZ ojuCqzDFiygJzt0OpZgU2qpmTu4tV2RXekFW/HLWNBURq8cyWj5rmT1ko2N7cmT8MXDc wGJQ== 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 p3-v6si422577plo.746.2018.03.19.11.40.39; Mon, 19 Mar 2018 11:40:53 -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 S1032186AbeCSSiv (ORCPT + 99 others); Mon, 19 Mar 2018 14:38:51 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:49694 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970296AbeCSSiR (ORCPT ); Mon, 19 Mar 2018 14:38:17 -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 404lF31WcszPjpJ; Mon, 19 Mar 2018 19:38:15 +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 boeck2.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3db:1800:60b5:55d8:d757:229 Received: from fau.de (p200300D503DB180060B555D8D7570229.dip0.t-ipconnect.de [IPv6:2003:d5:3db:1800:60b5:55d8:d757:229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX18pQEMWA13LMKm9VNIIe2NYrT1RlaPRzkI=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 404lDz6KG7zPk7s; Mon, 19 Mar 2018 19:38:11 +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, Christoph Hellwig Subject: [PATCH v2 11/11] block: sed-opal: check size of shadow mbr Date: Mon, 19 Mar 2018 19:36:53 +0100 Message-Id: <72e19ec70ffac23fff658c60eaae0db850150ca1.1521482296.git.jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: 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 problems or even damage with crappy firmwares. Signed-off-by: Jonas Rabenstein diff --git a/block/sed-opal.c b/block/sed-opal.c index 51f8034edbf7..9c73bd24c55f 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -1545,6 +1545,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 a constant value, it would be nice to * compute the actual value depending on IO_BUFFER_LENGTH -- 2.16.1