Received: by 2002:a05:7208:2202:b0:86:316c:7444 with SMTP id s2csp668086rbb; Fri, 31 May 2024 14:11:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxHV20rhIjpt5CosgekU8o8FwjRwk7KjrdLGLp+UVVlun2P+fl/sX3zu01h+8iZMd7Oms/iaAzb3ajdb8FVKTHa365Pa2xvbbAoxtQPw== X-Google-Smtp-Source: AGHT+IHpEnV3zxn+axgoPx06kwph9LkM8gOiK3q0I84xZkxfviTsvnN2ogRL+8onm4WVR81SDpZ3 X-Received: by 2002:a05:6a21:328d:b0:1af:d08d:da34 with SMTP id adf61e73a8af0-1b264bc9f4bmr10194830637.0.1717189898443; Fri, 31 May 2024 14:11:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717189898; cv=pass; d=google.com; s=arc-20160816; b=LIeOza4XikognftEsswmgr85kruSNCRMhFIHBFWwZi6I+fMj62F4S+vPnxQlSU31tU KQoVm9Jwuz4Bb7/F6qcnHVLfp/cylj41b4lQe7dwhdpFGw02xXGqHeBL1NGDvx1KGm/v sDkQO/g8ayH8OL8ZwDTY05caaefu722nXC/h2BD1CBqxrQSTwQNsa8AgNgi41/dYuiXr pfX6NwoW8vMkngAN8V+1UpvufBhs0gsKg9gBcYsqPm/bLD72EsRWjVADAqlB2l5t8Vhw EIceIpQD76cSe8XHU0sJ970oBZtZ6JVsNpe5NOVTDA6d8QeuNTIZI+QWtE5UST2Cr594 v+9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hlHKNskDmvqFaSo9xzpAYezf48F/OZL/Uhzy34r6Gh0=; fh=15ap1HczB9XHj3O25FWjWiC1/xh/uzWVOJ2eISFOerA=; b=xWfdl3B73LlZzbvC78FjhXIH2y0r8wXYKrFJGadM+RWSINoV3jjYA7GCPkTrRMB4ul aaadQELIrss1ttI3rxUkVxYwEi3RCewWb+cXsVqV3C4YvJTkdeTESJog6d3rrSTn83GG marr1/fEp5uXhaO+XHEkRY7sxirGKLW3qjpcwhCPY5iubK8F4wlyfhEWtVaELeXY44kR 5JVDfZRjyek+FUtDVzHUWw+lO7OTSKLF6MUtr6a88ybSmwbqq/X88Mk1S3bEhYR0GjY1 1zIvRponeiMgMJRUL4HRXCR19FGpo/PpsUXROAEXAVA9tjD+KrE8Jl9Ptod4Fdm7f/3+ lLYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JBMuE6+/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35d59da4fsi2152384a12.797.2024.05.31.14.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 14:11:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JBMuE6+/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 18EC8284DD2 for ; Fri, 31 May 2024 21:11:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C37E78C8F; Fri, 31 May 2024 21:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JBMuE6+/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFA15200B7; Fri, 31 May 2024 21:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717189849; cv=none; b=pyoQfbtdrNZ/Qa2kk37MKDDm39zHQe33kmfqAcvHKYveT5OTAUs6SD0SbuoJsghvqlPFqGaBuSqT7Ktol1yaO/Pc9fCVhCT+h5OKE+xer6CzxdDULymWlVKcz3BchWMZNHs5a8rM4aI7nIH7N7zMMAZZLt1ujW15Oj2uhbs2adY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717189849; c=relaxed/simple; bh=xlaiIZVQpnoQLjq8KYZChb3XAXfcj6FcTOal5RecnCg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lpCSr7wVCHaKY/FnlarQ7ZUIEG7qLyCDhb6vryKJSC8+zJEKj6prp8bsN+FcTbdyMNd+n5E4FRt2S6pwC+bDp74smjFZ2wnBjfDwdDWBYAzPMuhCyCl1xX9Rphq35BrZlfKYDbExJtxFl7j21maaOVfSMfBWEq0BtG71tkvS1bU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JBMuE6+/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F6AC116B1; Fri, 31 May 2024 21:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717189849; bh=xlaiIZVQpnoQLjq8KYZChb3XAXfcj6FcTOal5RecnCg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JBMuE6+/4uK+TfBRp2VQ6gOoUwebGVgcqfhkoGHoUJefQqxh51QCzFI3Z5dbVWeLD 1+Ha3PBzT2cZZ2kOrQAjGytheeq4zZw2jArSBrd0pZBvsyH6gBFr5vo8V9/k79eMHj rS+wliQZ4+w6cNAXFlLmFUMhyC4P+3Gb4PiJCKhJUiga77YamxslvCAy6Z0CtJUQSp LPQkiDQGV/M7AHdsKb8BBMobicc3+8zROKqAmKU/TxWZL7t2+PdnyNRYcEl8qad5yy aVZgYR2KWthC1Gt+72WCMsvracEBsCZ283+kvtfTazzYMTTizVHOwglKyqE8pTF2Nd LwGpAGJcspjkw== Date: Fri, 31 May 2024 15:10:45 -0600 From: Keith Busch To: Breno Leitao Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , "James E.J. Bottomley" , "Martin K. Petersen" , leit@meta.com, "open list:LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)" , "open list:LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)" , open list Subject: Re: [PATCH] mpt3sas: Avoid test/set_bit() operating in non-allocated memory Message-ID: References: <20240531180055.950704-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240531180055.950704-1-leitao@debian.org> On Fri, May 31, 2024 at 11:00:54AM -0700, Breno Leitao wrote: > diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c > index 258647fc6bdd..fe9f4a4175d1 100644 > --- a/drivers/scsi/mpt3sas/mpt3sas_base.c > +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c > @@ -8512,6 +8512,12 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) > ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); > if (ioc->facts.MaxDevHandle % 8) > ioc->pd_handles_sz++; > + /* pd_handles_sz should have, at least, the minimal room > + * for set_bit()/test_bit(), otherwise out-of-memory touch > + * may occur > + */ > + ioc->pd_handles_sz = ALIGN(ioc->pd_handles_sz, sizeof(unsigned long)); > + > ioc->pd_handles = kzalloc(ioc->pd_handles_sz, > GFP_KERNEL); > if (!ioc->pd_handles) { > @@ -8529,6 +8535,12 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) > ioc->pend_os_device_add_sz = (ioc->facts.MaxDevHandle / 8); > if (ioc->facts.MaxDevHandle % 8) > ioc->pend_os_device_add_sz++; > + > + /* pend_os_device_add_sz should have, at least, the minimal room > + * for set_bit()/test_bit(), otherwise out-of-memory may occur > + */ > + ioc->pend_os_device_add_sz = ALIGN(ioc->pend_os_device_add_sz, > + sizeof(unsigned long)); > ioc->pend_os_device_add = kzalloc(ioc->pend_os_device_add_sz, > GFP_KERNEL); > if (!ioc->pend_os_device_add) { Do we need similiar ALIGN for _base_check_ioc_facts_changes() too? Otherwise, yeah, the {test,set,clear}_bit() ops expect an address to something aligned to 'unsigned long'.