From: Jon Derrick <hidden> Date: 2017-02-15 19:42:14
Just a couple of fixes for sed-opal to prevent faulty firmware from
allowing us to go off in the weeds, and a helper to remove some
duplicate code.
v2->v3:
corrected the bad calculation on the response parser check and changed
it to only check the subpacket length
v1->v2:
left tok->len as a size_t
got everyone important on the same email thread
Jon Derrick (4):
block/sed: Use ssize_t on atom parsers to return errors
block/sed: Add helper to qualify response tokens
block/sed: Check received header lengths
MAINTAINERS: Remove powerpc's opal match
MAINTAINERS | 1 -
block/sed-opal.c | 124 +++++++++++++++++++++++++++----------------------------
2 files changed, 60 insertions(+), 65 deletions(-)
--
1.8.3.1
From: Jon Derrick <hidden> Date: 2017-02-15 19:42:16
The short atom parser can return an errno from decoding but does not
currently return the error as a signed value. Convert all of the parsers
to ssize_t.
Signed-off-by: Jon Derrick <redacted>
---
block/sed-opal.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
From: Jon Derrick <hidden> Date: 2017-02-15 19:42:21
Add a buffer size check against discovery and response header lengths
before we loop over their buffers.
Signed-off-by: Jon Derrick <redacted>
---
block/sed-opal.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
@@ -340,10 +340,17 @@ static int opal_discovery0_end(struct opal_dev *dev)conststructd0_header*hdr=(structd0_header*)dev->resp;constu8*epos=dev->resp,*cpos=dev->resp;u16comid=0;+u32hlen=be32_to_cpu(hdr->length);-print_buffer(dev->resp,be32_to_cpu(hdr->length));+print_buffer(dev->resp,hlen);-epos+=be32_to_cpu(hdr->length);/* end of buffer */+if(hlen>IO_BUFFER_LENGTH-sizeof(*hdr)){+pr_warn("Discovery length overflows buffer (%zu+%u)/%u\n",+sizeof(*hdr),hlen,IO_BUFFER_LENGTH);+return-EFAULT;+}++epos+=hlen;/* end of buffer */cpos+=sizeof(*hdr);/* current position on buffer */while(cpos<epos&&supported){
From: Jon Derrick <hidden> Date: 2017-02-15 19:42:22
Add helper which verifies the response token is valid and matches the
expected value. Merges token_type and response_get_token.
Signed-off-by: Jon Derrick <redacted>
---
block/sed-opal.c | 61 +++++++++++++++++++++++---------------------------------
1 file changed, 25 insertions(+), 36 deletions(-)
@@ -591,48 +591,25 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)return0;}-staticenumopal_response_tokentoken_type(conststructparsed_resp*resp,-intn)+staticconststructopal_resp_tok*response_get_token(+conststructparsed_resp*resp,+intn){conststructopal_resp_tok*tok;if(n>=resp->num){pr_err("Token number doesn't exist: %d, resp: %d\n",n,resp->num);-returnOPAL_DTA_TOKENID_INVALID;+returnERR_PTR(-EINVAL);}tok=&resp->toks[n];if(tok->len==0){pr_err("Token length must be non-zero\n");-returnOPAL_DTA_TOKENID_INVALID;+returnERR_PTR(-EINVAL);}-returntok->type;-}--/*-*Thisfunctionreturns0incaseofinvalidtoken.Oneshouldcall-*token_type()firsttofindoutifthetokenisvalidornot.-*/-staticenumopal_tokenresponse_get_token(conststructparsed_resp*resp,-intn)-{-conststructopal_resp_tok*tok;--if(n>=resp->num){-pr_err("Token number doesn't exist: %d, resp: %d\n",-n,resp->num);-return0;-}--tok=&resp->toks[n];-if(tok->len==0){-pr_err("Token length must be non-zero\n");-return0;-}--returntok->pos[0];+returntok;}staticssize_tresponse_parse_tiny(structopal_resp_tok*tok,
From: Jon Derrick <hidden> Date: 2017-02-15 19:42:28
PPC's 'opal' match pattern also matches block/sed-opal.c, where it looks
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
Signed-off-by: Jon Derrick <redacted>
---
MAINTAINERS | 1 -
1 file changed, 1 deletion(-)
From: Scott Bauer <hidden> Date: 2017-02-15 21:14:40
On Wed, Feb 15, 2017 at 12:42:06PM -0700, Jon Derrick wrote:
The short atom parser can return an errno from decoding but does not
currently return the error as a signed value. Convert all of the parsers
to ssize_t.
Signed-off-by: Jon Derrick <redacted>
From: Scott Bauer <hidden> Date: 2017-02-15 21:29:32
On Wed, Feb 15, 2017 at 12:42:07PM -0700, Jon Derrick wrote:
quoted hunk
Add helper which verifies the response token is valid and matches the
expected value. Merges token_type and response_get_token.
Signed-off-by: Jon Derrick <redacted>
---
block/sed-opal.c | 61 +++++++++++++++++++++++---------------------------------
1 file changed, 25 insertions(+), 36 deletions(-)
@@ -591,48 +591,25 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)return0;}-staticenumopal_response_tokentoken_type(conststructparsed_resp*resp,-intn)+staticconststructopal_resp_tok*response_get_token(+conststructparsed_resp*resp,+intn){conststructopal_resp_tok*tok;if(n>=resp->num){pr_err("Token number doesn't exist: %d, resp: %d\n",n,resp->num);-returnOPAL_DTA_TOKENID_INVALID;+returnERR_PTR(-EINVAL);}tok=&resp->toks[n];if(tok->len==0){pr_err("Token length must be non-zero\n");-returnOPAL_DTA_TOKENID_INVALID;+returnERR_PTR(-EINVAL);}-returntok->type;-}--/*-*Thisfunctionreturns0incaseofinvalidtoken.Oneshouldcall-*token_type()firsttofindoutifthetokenisvalidornot.-*/-staticenumopal_tokenresponse_get_token(conststructparsed_resp*resp,-intn)-{-conststructopal_resp_tok*tok;--if(n>=resp->num){-pr_err("Token number doesn't exist: %d, resp: %d\n",-n,resp->num);-return0;-}--tok=&resp->toks[n];-if(tok->len==0){-pr_err("Token length must be non-zero\n");-return0;-}--returntok->pos[0];+returntok;}staticssize_tresponse_parse_tiny(structopal_resp_tok*tok,
This is sorta pedantic but from my reading of the code token can never be null. It will
either be a valid pointer or ERR_PTR(-EINVAL), but never null.
So maybe change this to IS_ERR(token) etc. Other than that little nit:
Reviewed-by: Scott Bauer <redacted>
From: Stewart Smith <hidden> Date: 2017-02-16 00:37:35
Jon Derrick [off-list ref] writes:
PPC's 'opal' match pattern also matches block/sed-opal.c, where it looks
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
This patch will end up missing some code, what about this instead:
Remove OPAL regex in powerpc to avoid false match
Signed-off-by: Stewart Smith <redacted>
---
MAINTAINERS | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
From: Andrew Donnellan <hidden> Date: 2017-02-16 01:01:22
On 16/02/17 11:37, Stewart Smith wrote:
Jon Derrick [off-list ref] writes:
quoted
PPC's 'opal' match pattern also matches block/sed-opal.c, where it looks
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
This patch will end up missing some code, what about this instead:
Remove OPAL regex in powerpc to avoid false match
Signed-off-by: Stewart Smith <redacted>
Per my reply to v4 of this series, your list matches mine. With the one
typo correction below:
Reviewed-by: Andrew Donnellan <redacted>
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2017-02-16 05:23:47
Jon Derrick [off-list ref] writes:
PPC's 'opal' match pattern also matches block/sed-opal.c, where it looks
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
We thought of it first.
Can't you just rename your driver, Opal Storage Specification, so "oss",
that should be pretty unique?
... :)
I don't like this version, but I'll merge the one from Stewart which
drops the pattern and adds the paths for the existing drivers.
cheers
From: Jon Derrick <hidden> Date: 2017-02-16 16:14:45
Thanks everyone. Sorry about the mess :)
On 02/15/2017 10:23 PM, Michael Ellerman wrote:
Jon Derrick [off-list ref] writes:
quoted
PPC's 'opal' match pattern also matches block/sed-opal.c, where it looks
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
We thought of it first.
Can't you just rename your driver, Opal Storage Specification, so "oss",
that should be pretty unique?
... :)
I don't like this version, but I'll merge the one from Stewart which
drops the pattern and adds the paths for the existing drivers.
cheers
From: Elliott, Robert (Persistent Memory) <hidden> Date: 2017-02-17 16:41:01
-----Original Message-----
From: linux-block-owner@vger.kernel.org [mailto:linux-block-
owner@vger.kernel.org] On Behalf Of Jon Derrick
Sent: Thursday, February 16, 2017 10:15 AM
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Jens Axboe <axboe@kernel.dk>; Rafael Antognolli
[off-list ref]; Greg Kroah-Hartman
[off-list ref]; linux-kernel@vger.kernel.org; linux-
block@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; Christoph Hellwig
[off-list ref]; Scott Bauer [off-list ref]
Subject: Re: [PATCHv3 4/4] MAINTAINERS: Remove powerpc's opal match
=20
Thanks everyone. Sorry about the mess :)
=20
On 02/15/2017 10:23 PM, Michael Ellerman wrote:
quoted
Jon Derrick [off-list ref] writes:
quoted
PPC's 'opal' match pattern also matches block/sed-opal.c, where it loo=
ks
quoted
quoted
like the 'arch/powerpc' file pattern should be enough to match powerpc
opal code by itself. Remove the opal regex pattern from powerpc.
We thought of it first.
Can't you just rename your driver, Opal Storage Specification, so "oss"=
,
quoted
that should be pretty unique?
... :)
The library could easily be used for devices supporting the Opalite and Pyr=
ite=20
SSCs, not just the Opal SSC. With some effort, I suspect that Enterprise SS=
C
could also be supported. So, a broader name might indeed be useful.
The full names of the specifications are:
TCG Storage Security Subsystem Class: Opal
TCG Storage Security Subsystem Class: Opalite
TCG Storage Security Subsystem Class: Pyrite
TCG Storage Security Subsystem Class: Enterprise
---
Robert Elliott, HPE Persistent Memory