Received: by 10.223.185.116 with SMTP id b49csp7425378wrg; Thu, 1 Mar 2018 05:28:05 -0800 (PST) X-Google-Smtp-Source: AG47ELvb045D4KHIyR+Ag4cq8AdplcxwwyGJTH+RVXFMsb/YxdRqPL2OrIogAYVlpEBsadc9mKI8 X-Received: by 2002:a17:902:32a2:: with SMTP id z31-v6mr2001494plb.32.1519910885488; Thu, 01 Mar 2018 05:28:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519910885; cv=none; d=google.com; s=arc-20160816; b=w+vt1NL8hQvOTHl/c7Iq45+pnTRpMcVVWI4AsaLfeGWZDaA0ZqP6FNqqaoC5yDllnR G/yYx2cuG+3vAYckmBRa2X40QcFzqG1w5sYQNrfqWhxZvDe3F5fd6d40ag4nlDKQi8n7 609lPYvjXHK3RohM7/aaUkkSHxrwiejzTq/er/17MjA8sPrDO9IGtsxJHffbLXAtqnwQ XYlmNfNwjgaiyZ17KGoJJrZGJta89e/oA91Tz5PlmIE4wso0Wc6PS/ZvvjFMf+xzKYQN oUxFfFCMVeLitcTVBTaNNOYcqljqy/9s49vVljc+5sNaeZAHcpnFEGnk8aEjVNl+nE8W W0iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=n8fVEY1XRDqu59MsPy+ikaHg40xtGxL/CoBNSY6Apyg=; b=0zd9ikyEINbTT7Jw4bgBz7jcFGjEZjVtGnfJRZqfvFb0RmSo0vZDP6Xa75YcRDtB/F E6iQta7fb8x014EwJb2I4UwT1AbDjGAtHTKZbww0f4wokowwM6Zxm5eNleaCwrchPIUr y18W0tY5xV4KJpW7oinDCfAoqx0IgLzf/h3Nmd3KRkhEEriUJnzAVivlfl/XaZmfwt1N cXLWEkGJeuDxSh6RyRAlgxFYrPsYUSv1R67bu40YCwmIXNIQNgEMK6ilmuJuvnGTl7Fy ACiqhEC4UnjgDW8yMhtEHxQFwuQ4pNZnD027RTZQZ61CDzM7cXh+q8q0dyBlVV4I4YHF EpNQ== 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 k69si2470389pgd.354.2018.03.01.05.27.50; Thu, 01 Mar 2018 05:28:05 -0800 (PST) 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 S1030674AbeCAN1E (ORCPT + 99 others); Thu, 1 Mar 2018 08:27:04 -0500 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:47033 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030379AbeCAN1C (ORCPT ); Thu, 1 Mar 2018 08:27:02 -0500 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 3zsYBC5wWFzPlSF; Thu, 1 Mar 2018 14:26:59 +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-Virus-Scanned: amavisd-new at boeck4.rrze.uni-erlangen.de (RRZE) X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 217.238.5.165 Received: from fau.de (pD9EE05A5.dip0.t-ipconnect.de [217.238.5.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX19rXHpgVfUleVqfQB5+mgWJwSkCe+Bme+0=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 3zsYB81ylDzPlTV; Thu, 1 Mar 2018 14:26:56 +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][RESEND] block: sed-opal: fix response string extraction Date: Thu, 1 Mar 2018 14:26:37 +0100 Message-Id: <20180301132637.1230-1-jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tokens are prefixed by a variable length of bytes. If a bytestring is not stored in an tiny or short atom, we have to skip more than one byte in order to have the actual bytes not prefixed by the bytes describing the actual length of the string. Signed-off-by: Jonas Rabenstein --- block/sed-opal.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/block/sed-opal.c b/block/sed-opal.c index 525506bed399..33052d0111de 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -876,6 +876,9 @@ static int response_parse(const u8 *buf, size_t length, static size_t response_get_string(const struct parsed_resp *resp, int n, const char **store) { + u8 skip; + const struct opal_resp_tok *token; + *store = NULL; if (!resp) { pr_debug("Response is NULL\n"); @@ -888,13 +891,30 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, return 0; } - if (resp->toks[n].type != OPAL_DTA_TOKENID_BYTESTRING) { + token = &resp->toks[n]; + if (token->type != OPAL_DTA_TOKENID_BYTESTRING) { pr_debug("Token is not a byte string!\n"); return 0; } - *store = resp->toks[n].pos + 1; - return resp->toks[n].len - 1; + switch (token->width) { + case OPAL_WIDTH_TINY: + case OPAL_WIDTH_SHORT: + skip = 1; + break; + case OPAL_WIDTH_MEDIUM: + skip = 2; + break; + case OPAL_WIDTH_LONG: + skip = 4; + break; + default: + pr_debug("Token has invalid width!\n"); + return 0; + } + + *store = token->pos + skip; + return token->len - skip; } static u64 response_get_u64(const struct parsed_resp *resp, int n) -- 2.13.6