Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13368085pxu; Sun, 3 Jan 2021 12:00:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWfFFTTSPKtgkO9GP7ncUo+2uxkPLEBpckDgK+/AqBwcQWIrbst8tK19+NHaYaUzKcOEkj X-Received: by 2002:a17:906:76c9:: with SMTP id q9mr14171949ejn.484.1609704025670; Sun, 03 Jan 2021 12:00:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609704025; cv=none; d=google.com; s=arc-20160816; b=sttfYGimkHrzAGLPkO28xucSrH5S22o3Do61Lkr9jeqtogI3rM7HjbNrJAltwdVOQj hFZgQX+G/Rpd2VRRsgloDDH6BYd2V3l75tlSEwNLJgwHnVVONzURaWlslfCzYnFL4edo eN4tvqPgCdxpx3ixBM6x2+E6H1oXawV3unz6qz8Q5Z8hf6WA1S/BnSe0MJmUpMRPxzNB 7cNgUQF3yiUg+hO+3Q/CKcsyMcmnEBb2gJTn/Qr/WqM624DX4lWm+U7Ul0g3KyJFi6GD o7/LMk1hgmqi+eKNAXomBaQ1uzAteTw+YAsj53Ly3C5O0vpwK6ciJrj24EmfvPA5cOaR qk7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+6+VywEg8/gU2v6sz3PQy/y+0HMrzqbbii6Z1MwHHJ0=; b=0u2F6OggRER6iq/ClDzoVvf4ZGM0vTqxMX89CBXbTsTzG7WjJtsSt10v+eskNyBZjZ ZNIcDNTzGT8ck9Uhw6prhhAM0BeUtj+Hm6lqz2EsG/8FSbnTpHkI9xmlFZoaNDP0MZ6H kBBkYretZF9HbJqP9dcQ18QOiXX0lAdM79/gioQuJbcuSfGEu3eYD3kJXSivl3qAeBQQ j+KzHC1lm+6mWrFIHE27o+asXFjugwGX4QqzzBUebMFi2S/3yXcr/9KA1lR7dc1sKX6r YetxGLROjCBg8mD/WUEDTUmSHCIywa9p4cdszTmoZ0PJj/4sLWiVxbbl9/L3dZbrYvGw 4N+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iBw5o8/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si28950817ejd.473.2021.01.03.12.00.02; Sun, 03 Jan 2021 12:00:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iBw5o8/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbhACQ11 (ORCPT + 99 others); Sun, 3 Jan 2021 11:27:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:57496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbhACQ10 (ORCPT ); Sun, 3 Jan 2021 11:27:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CEF4E20C56; Sun, 3 Jan 2021 16:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609691205; bh=9RwAdYgsGbMkZI/sgXYkv2BpzryRIXETFKxEQ7M3MtQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iBw5o8/5JnIbKy81jRxWQVc0rT84WXhMHgUtmt7KguQiT2JrvY+MqskctBBqKfsjE p/zRRRCn89kwkiH0+o4Y+Qv1xqll9ZXC1/kvFjw9MgwaQp38RQeLaOikEcdv4oxZpb FXlPSbg6CgJiYn/GDqiZOAtZUO7S6Xmt0QiBSfKqp8IbT8Smw+a0o9BGs31zSg7FF8 zLG/DPAulW+TplITiQIKwAEDAxRKqAvGAuP+iMWXUD8eUzjdb3w22/cW63wlUftrtR DRKTODujIyDe0poBO1BJd4l+QGAL+liNy8W7Sk8kyNTW6yFngQIibbbbQGgU8Wnq7v 4HjeYkwhQLJ7g== Received: by mail-oi1-f173.google.com with SMTP id d203so29428563oia.0; Sun, 03 Jan 2021 08:26:45 -0800 (PST) X-Gm-Message-State: AOAM5339WNpMEs6Bd0EIia1J6PpEuFC1o1/4JcHtMGoGil56wxy7CTm0 hwguuyM4v/HxEBdSaPijhEJZBk7FwUG/S64UEKI= X-Received: by 2002:aca:44d:: with SMTP id 74mr16023653oie.4.1609691205172; Sun, 03 Jan 2021 08:26:45 -0800 (PST) MIME-Version: 1.0 References: <20200908213715.3553098-1-arnd@arndb.de> <20200908213715.3553098-2-arnd@arndb.de> <20201231001553.GB16945@home.linuxace.com> In-Reply-To: <20201231001553.GB16945@home.linuxace.com> From: Arnd Bergmann Date: Sun, 3 Jan 2021 17:26:29 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/3] scsi: megaraid_sas: check user-provided offsets To: Phil Oester Cc: Arnd Bergmann , Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , Christoph Hellwig , "# 3.4.x" , Anand Lodnoor , Chandrakanth Patil , Hannes Reinecke , megaraidlinux.pdl@broadcom.com, linux-scsi , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 31, 2020 at 1:15 AM Phil Oester wrote: > > On Tue, Sep 08, 2020 at 11:36:22PM +0200, Arnd Bergmann wrote: > > It sounds unwise to let user space pass an unchecked 32-bit > > offset into a kernel structure in an ioctl. This is an unsigned > > variable, so checking the upper bound for the size of the structure > > it points into is sufficient to avoid data corruption, but as > > the pointer might also be unaligned, it has to be written carefully > > as well. > > > > While I stumbled over this problem by reading the code, I did not > > continue checking the function for further problems like it. > > Sorry for replying to an ancient thread, but this patch just recently > made it into 5.10.3 and has caused unintended consequences. On Dell > servers with PERC RAID controllers, booting 5.10.3+ with this patch > causes a PCI parity error. Specifically: > > Event Message: A PCI parity error was detected on a component at bus 0 device 5 function 0. > Severity: Critical > Message ID: PCI1308 > > I reverted this single patch and the errors went away. > > Thoughts? Thank you for the report and bisecting the issue, and sorry this broke your system! Fortunately, the patch is fairly small, so there are only a limited number of things that could go wrong. I haven't tried to analyze that message, but I have two ideas: a) The added ioc->sense_off check gets triggered and the code relies on the data being written outside of the structure b) the address actually needs to always be written as a 64-bit value regardless of the instance->consistent_mask_64bit flag, as the driver did before. This looked like it was done in error. Can you try the patch below instead of the revert and see if that resolves the regression, and if it triggers the warning message I add? Arnd diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 6e4bf05c6d77..248063a4148b 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -8194,8 +8194,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, /* make sure the pointer is part of the frame */ if (ioc->sense_off > (sizeof(union megasas_frame) - sizeof(__le64))) { - error = -EINVAL; - goto out; + pr_warn("possible out of bounds access offset %d\n", ioc->sense_off); } sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, @@ -8209,7 +8208,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, if (instance->consistent_mask_64bit) put_unaligned_le64(sense_handle, sense_ptr); else - put_unaligned_le32(sense_handle, sense_ptr); + put_unaligned_le64(sense_handle, sense_ptr); } /*