Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5075402imm; Tue, 16 Oct 2018 04:57:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV62HV7rw02Zt643fJof1wC/Z5ZguEZePYKAcu79mFUnPrxlbsAijeNkqs6os+dLXssZZffZu X-Received: by 2002:a63:682:: with SMTP id 124-v6mr20119849pgg.52.1539691073411; Tue, 16 Oct 2018 04:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539691073; cv=none; d=google.com; s=arc-20160816; b=0uhRpCttSjMWf+AtCx3O5mlcGX6gpK76MGikm+pnqUMuyUhVN1L/bFjEb71qioE6mr kjrMWT1iyqiQsrwmjruhTE4wmGGxvWLEzlg9q6/bhQHrfzGK2eznPeNSpdQrxEmh3OKT YAw5pxVVGYmwMHs4RY0tbXQJBvXhxPfAsf/aXnsk4g9ckrnP+Tq5TPhOJLzN39y4i1DY +sgbaZRem8P+GuTXlnGqMlSxk/nZwrNOBo0Ntv+QsTeqH6arFn259Hlr/YBjwGS9Bg9C rqPFTV3PO8CjRrYlg0iOaREuwSTNwPFTcsEujBSE2iJ859gBEy3s7dUtFK98h4OAjaj+ yOvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gIQobr/MsuX+iW/Aneb0dR7d9vo4B4vgjtKsuW0y+m4=; b=rmi162jCPRbiVvsyJEvyMuB64P7Y1d1UtWwibhFll/lmKc5A25gVhcs1Mh5Hi52VYb T76bwSEu0leDOA2zMuNxXl7cRyg7hqQnbhmK9zlmSkBKA6P2Qmerb4NYSepsmo+NDWzn M9rVUffaSChNDPpzIh632d6PGnIvrZ686OBBy4mmxyxf9oTnMe0x7B+7WVS6hZ6TBFR5 HAxwKdtpDwJExpoOiqx/ZK1DCzC/q7BDVcS5rvejqn1bFN7NgjTYDNeg+hs/WByWPAFu 4L4P9DM/B7BU+iZleiOXz7KaQUwjgxuBiHgq7t5LUDONAWLzUwSDebx1yslyDSRJGhNK nJXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=b67N66qY; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11-v6si12299495pgm.572.2018.10.16.04.57.37; Tue, 16 Oct 2018 04:57: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; dkim=pass header.i=@broadcom.com header.s=google header.b=b67N66qY; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbeJPTrO (ORCPT + 99 others); Tue, 16 Oct 2018 15:47:14 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:39132 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbeJPTrO (ORCPT ); Tue, 16 Oct 2018 15:47:14 -0400 Received: by mail-ed1-f67.google.com with SMTP id d15-v6so21022244edq.6 for ; Tue, 16 Oct 2018 04:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gIQobr/MsuX+iW/Aneb0dR7d9vo4B4vgjtKsuW0y+m4=; b=b67N66qYzFcvR1ujwdnBHc6PERhJG4Z8leXGV4xRjZMY7RzWbgDNx7UVOrk5tGIId+ QMj8/S+WicAwj+FQkzwGdUjNVKBedWurP+TdFLANrs7lclpFwnlUHaGXYg02jqJgyMx2 WEO00qqTJnGRgGJAjgAUB/Dt6izQWCkie0WGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gIQobr/MsuX+iW/Aneb0dR7d9vo4B4vgjtKsuW0y+m4=; b=WbZjqSC/4/Oe1dBuEfJPPmElxupznraRSChf7JZx5lumW72xnT4pdTdQAKkgzXFkcp 8+hxzMEE7Zmmldw4B0+zRdmlWTyZhdVlWpOsRC8iMj+zvRyAj5PTbGB16if2pzdSh9bA X6/1NG0Bi1TJ7XgFdAN2323vGDQhCB8IHoG8Ex7NjlFWhZWnjNk3pmcJ7cTr27TyWtUG 2CZXFEU4CvrVNA8g7bMVKTozSsIxcH6yCKd+ciysO/EKNbW1xUoRcVE6w252QXBCAXGw t85syasmwmO8WX0xNgH4lPJQK/itQJL77rPbbDeXbJ7q8EIQfQw8u8b7Hdj8XQ+oFmhC 9+Uw== X-Gm-Message-State: ABuFfoh/IKMtI0Vgn58AwYipRRo0FJHQt2b/qQ/+s0eov/Y4DpDvg4gb LAEsOrT55G8UBK8yM/Skm+/Q7IFHPXXX3ok8+9YJlg== X-Received: by 2002:a17:906:4054:: with SMTP id y20-v6mr23192497ejj.30.1539691025160; Tue, 16 Oct 2018 04:57:05 -0700 (PDT) MIME-Version: 1.0 References: <1538850861-26882-1-git-send-email-wang6495@umn.edu> In-Reply-To: <1538850861-26882-1-git-send-email-wang6495@umn.edu> From: Sumit Saxena Date: Tue, 16 Oct 2018 17:26:54 +0530 Message-ID: Subject: Re: [PATCH] scsi: megaraid_sas: fix a missing-check bug To: wang6495@umn.edu Cc: kjlu@umn.edu, Kashyap Desai , Shivasharan Srikanteshwara , "James E. J. Bottomley" , "Martin K. Petersen" , "PDL,MEGARAIDLINUX" , Linux SCSI List , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 7, 2018 at 12:04 AM Wenwen Wang wrote: > > In megasas_mgmt_compat_ioctl_fw(), to handle the structure > compat_megasas_iocpacket 'cioc', a user-space structure megasas_iocpacket > 'ioc' is allocated before megasas_mgmt_ioctl_fw() is invoked to handle the > packet. Since the two data structures have different fields, the data is > copied from 'cioc' to 'ioc' field by field. In the copy process, > 'sense_ptr' is prepared if the field 'sense_len' is not null, because it > will be used in megasas_mgmt_ioctl_fw(). To prepare 'sense_ptr', the > user-space data 'ioc->sense_off' and 'cioc->sense_off' are copied and saved > to kernel-space variables 'local_sense_off' and 'user_sense_off' > respectively. Given that 'ioc->sense_off' is also copied from > 'cioc->sense_off', 'local_sense_off' and 'user_sense_off' should have the > same value. However, 'cioc' is in the user space and a malicious user can > race to change the value of 'cioc->sense_off' after it is copied to > 'ioc->sense_off' but before it is copied to 'user_sense_off'. By doing so, > the attacker can inject different values into 'local_sense_off' and > 'user_sense_off'. This can cause undefined behavior in the following > execution, because the two variables are supposed to be same. > > This patch enforces a check on the two kernel variables 'local_sense_off' > and 'user_sense_off' to make sure they are the same after the copy. In case > they are not, an error code EINVAL will be returned. > > Signed-off-by: Wenwen Wang > --- > drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c > index 9aa9590..f6de752 100644 > --- a/drivers/scsi/megaraid/megaraid_sas_base.c > +++ b/drivers/scsi/megaraid/megaraid_sas_base.c > @@ -7523,6 +7523,9 @@ static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) > get_user(user_sense_off, &cioc->sense_off)) > return -EFAULT; > > + if (local_sense_off != user_sense_off) > + return -EINVAL; > + > if (local_sense_len) { > void __user **sense_ioc_ptr = > (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); Acked-by: Sumit Saxena > -- > 2.7.4 >