From: Borislav Petkov <bp@alien8.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
Ching Huang <ching2048@areca.com.tw>,
Hannes Reinicke <hare@suse.de>,
Johannes Thumshirn <jthumshirn@suse.de>,
Tomas Henzl <thenzl@redhat.com>,
linux-scsi@vger.kernel.org, security@kernel.org
Subject: Re: [patch v2] arcmsr: buffer overflow in arcmsr_iop_message_xfer()
Date: Fri, 23 Sep 2016 13:22:26 +0200 [thread overview]
Message-ID: <20160923112226.rteir5ivjou64ffh@pd.tnic> (raw)
In-Reply-To: <yq17fadz2l6.fsf@sermon.lab.mkp.net>
On Thu, Sep 15, 2016 at 09:59:01AM -0400, Martin K. Petersen wrote:
> >>>>> "Dan" == Dan Carpenter <dan.carpenter@oracle.com> writes:
>
> Dan> We need to put an upper bound on "user_len" so the memcpy() doesn't
> Dan> overflow.
>
> Applied to 4.9/scsi-queue.
Yap, Tomas said the kfree was missing on the error path but can we
simplify this further by doing the user_len check first so that the
kfree() is not even needed?
Patch ontop:
---
From: Borislav Petkov <bp@suse.de>
Date: Fri, 23 Sep 2016 13:04:51 +0200
Subject: [PATCH] scsi: arcmsr: Simplify user_len checking
Do the user_len check first and then the ver_addr allocation so that
we can save us the kfree() on the error path when user_len is >
ARCMSR_API_DATA_BUFLEN.
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Marco Grassi <marco.gra@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Tomas Henzl <thenzl@redhat.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
---
drivers/scsi/arcmsr/arcmsr_hba.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 110eca9eaca0..3d53d636b17b 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -2391,18 +2391,20 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
uint32_t user_len;
int32_t cnt2end;
uint8_t *pQbuffer, *ptmpuserbuffer;
- ver_addr = kmalloc(ARCMSR_API_DATA_BUFLEN, GFP_ATOMIC);
- if (!ver_addr) {
+
+ user_len = pcmdmessagefld->cmdmessage.Length;
+ if (user_len > ARCMSR_API_DATA_BUFLEN) {
retvalue = ARCMSR_MESSAGE_FAIL;
goto message_out;
}
- ptmpuserbuffer = ver_addr;
- user_len = pcmdmessagefld->cmdmessage.Length;
- if (user_len > ARCMSR_API_DATA_BUFLEN) {
+
+ ver_addr = kmalloc(ARCMSR_API_DATA_BUFLEN, GFP_ATOMIC);
+ if (!ver_addr) {
retvalue = ARCMSR_MESSAGE_FAIL;
- kfree(ver_addr);
goto message_out;
}
+ ptmpuserbuffer = ver_addr;
+
memcpy(ptmpuserbuffer,
pcmdmessagefld->messagedatabuffer, user_len);
spin_lock_irqsave(&acb->wqbuffer_lock, flags);
--
1.8.5.2
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
next prev parent reply other threads:[~2016-09-23 11:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAFkTriJHaO0-O0AXKWSZW6bXT_2m+VqRdwshFsgeq1=Bjfn_OQ@mail.gmail.com>
2016-09-15 12:01 ` [patch] arcmsr: buffer overflow in arcmsr_iop_message_xfer() Dan Carpenter
2016-09-15 13:19 ` Tomas Henzl
2016-09-15 13:43 ` Dan Carpenter
2016-09-15 13:44 ` [patch v2] " Dan Carpenter
2016-09-15 13:59 ` Martin K. Petersen
2016-09-23 11:22 ` Borislav Petkov [this message]
2016-09-26 11:58 ` Johannes Thumshirn
2016-09-26 13:29 ` Tomas Henzl
2016-09-27 1:08 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160923112226.rteir5ivjou64ffh@pd.tnic \
--to=bp@alien8.de \
--cc=ching2048@areca.com.tw \
--cc=dan.carpenter@oracle.com \
--cc=hare@suse.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=jthumshirn@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=security@kernel.org \
--cc=thenzl@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).