Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp942931pxb; Sun, 22 Aug 2021 00:55:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAEUCfInbsZLdK3mIXn0N22AYeDd/afYQuLhYbjI62uG/69ubrmXTXawKIgL8msratZoEz X-Received: by 2002:a17:906:150c:: with SMTP id b12mr30006761ejd.275.1629618924787; Sun, 22 Aug 2021 00:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629618924; cv=none; d=google.com; s=arc-20160816; b=UiSZyLCNjgbpxGWjaWI75L5b5fLvj6dyqwWi0Pg9Ffmqd6MiWvhFAzUmAvH66aUHHm LWo0ZmKQ6A56u4x/V3Du76HexYCu36LOeKW+ABXY4/ZIxV1CvKiq5xX+9DvR3hl8Nt4+ Nga29njBvwy5tZ1XQd7tPz36yzRhoEPVhN6pBBYhr3N6H3TBbemz9IDxe3aaSOz29QRx 58csgoNDoO7DrulkINYaEVhtOiLN7vFD9/DV/c9DKE29WTCeNlxkOkqa99JoFXhBpO97 Cgq/oFEVZ55tYkLVE+Jc3qpqMBmm9ps5BdyJi+v1TfOCa11fpN9+T/rcwDcIK75jeO0O lZHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kwHDlRYGw2pe2VpozCEASD85dDS6sHxCPa/xDSIICvM=; b=MfAEmCD6sb4ZKfC8p4Iyd/+Tgz+rmtt4qnCsL+fFlQTI37HapuwCzZgqE2qJfXedwp I+goeFHfcLNe7aU//j5kgurIouwoiLF4F8mKX8clQdgOXRBup4o8sGvp8a0Z75bKeRIJ +BQ+hHaVinBPL+hovQ0Kb+p/Qy+I9/0pFhoUfQTacWjrR1Mqj9tOSO2449qs7gI4Zkl4 r7lirFC2/uJurVBg6btTRjQNtOtAreiLGQKBdFMSQxGALvLqDcGd7BZ1Juqqhn3I2RS3 ++d0EB1jwt2LGnSWf8W/sBIYg/Tjk1IOiJHtPME+bbGgMhRH297hKCOr24kFF/oV+cPP tdlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VJB3FTt5; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s27si10911752edw.384.2021.08.22.00.55.02; Sun, 22 Aug 2021 00:55:24 -0700 (PDT) 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=@chromium.org header.s=google header.b=VJB3FTt5; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232169AbhHVHwR (ORCPT + 99 others); Sun, 22 Aug 2021 03:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbhHVHwK (ORCPT ); Sun, 22 Aug 2021 03:52:10 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B03A9C061756 for ; Sun, 22 Aug 2021 00:51:29 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id x1so5809602plg.10 for ; Sun, 22 Aug 2021 00:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kwHDlRYGw2pe2VpozCEASD85dDS6sHxCPa/xDSIICvM=; b=VJB3FTt5q3R3nGTwAgDC29A/KPNoR+UpkxoBw0Dq4oRvBhiadsp7xDfQYieHFnlYbk 4FxWfTV91NYwkFNCEBLbyPpmTlxrZQr0gC271DLHzeiQnbnlhlxApp/G+sbOQk8iU7Eg P4t+2DpWPq78fX+VsMvxWmM5/zw7BIsDMwPjo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kwHDlRYGw2pe2VpozCEASD85dDS6sHxCPa/xDSIICvM=; b=ISvVQB6JajHfVZ87MmlNhYIxySPQlfZ6Ga9vGr3Zq5S6W/ODcrAv7Gz2IpDzzNn3+x WKhsH3VellKoqZ/hFZgcPSqcotgVIlrDYuQYTKTMce+be6zOagunOZHiVa5sXN9MfFtc Wqj5HTMgScpPS3pitgbqTJcQHPQkO6j9sRaqUPRU+51uy6sgQR5XF8Oq157vW5qRMUdm 3imrqACc+F4mqMChJTvDt3sqHpqIi/Sp7/9fXG7HYLlqlNGpKgPXU+eBMMixugsBY/AU T95onNquBAZaVI+9fe2Y43GgDSrwBqhy1Xe7O1cyuAONLM+g/tmgqh3lfRipyq6JqllM +1nw== X-Gm-Message-State: AOAM531PGbA1hX+drqtgcCPOxayNgz4x3YkDSFP6iNQup56tIXbEMoXo NClOqHMvZZWlRQNRmGQl34x/TQ== X-Received: by 2002:a17:90a:1f09:: with SMTP id u9mr13451822pja.206.1629618689283; Sun, 22 Aug 2021 00:51:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j5sm16177432pjv.56.2021.08.22.00.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Aug 2021 00:51:27 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Tyrel Datwyler , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Rasmus Villemoes , Daniel Micay , Francis Laniel , Bart Van Assche , David Gow , linux-mm@kvack.org, clang-built-linux@googlegroups.com, linux-hardening@vger.kernel.org Subject: [PATCH for-next 01/25] scsi: ibmvscsi: Avoid multi-field memset() overflow by aiming at srp Date: Sun, 22 Aug 2021 00:50:58 -0700 Message-Id: <20210822075122.864511-2-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210822075122.864511-1-keescook@chromium.org> References: <20210822075122.864511-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1793; h=from:subject; bh=ug7KtAnqHA97F0XIHxj84B1vcjl5KTaHRbDt5BL2iJc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhIgH029iMytTOfEkySdRelPdaDhR6VhLaGeRkdoDa 4ABOm4yJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYSIB9AAKCRCJcvTf3G3AJjv2D/ 48Fr/XBXtchVss+4cH6PQaHpgRQzDXtB1e3n+pg90FdtK9Gu2IOW5Eeo4HeRN99/sieQG+UcSe490f qdjzZblkN7rCOZs5uC7Qv2WpSpX0BBhVlJiGfxEbCTMtN/McHWDMfDGmctuVYCjiFd7y7Qpjh/L95Y m7MEuz01lgiYVwA7kXYcrKV101D+aRlU+gawH0a187wiLOGq8y3BJAooZKrFbYl1355a2kJZCjPGoC hfz0Zlx7XRVAVlQj2eCSdwACSCDiDmZx+gKHkVGAa0CtgE0F32xohvWP2x4Yt3yFRHQZDV+m2xqDvg jdu7NtA6bQe03uJ61mDeZEZmxbYOgkiliI38njvH83Gv+Oio1sCmUJjxyDGm325T/wynBN5hbw25If e7zPYndMKDwfXXY+dtyCHCMOh0rwCnS8C5qg3Z+ez6sc/fc1H3oGeSo4BsvngOPFd0iFMrdzhmT9Y4 eXJZW8YHVV7l2UMynV+iVHszGnG5p93QrqnK5KN++aRu+Vr8WKiP9AlwHb8ALA+9vT6sy4fojF/6p1 yL/9kO9S1YrHvKzdaJA1a0FZiq0azd5ExdJrqy3oB43u2iZm/iUYWiea6jYZ0NIrVuHaNcIy9Dn8By CUJjki1mhqlzaYinYiWB2xUvQmLUuuYrVcDc6adS96luBv0lQeyKTVjBPPdw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memset(), avoid intentionally writing across neighboring fields. Instead of writing beyond the end of evt_struct->iu.srp.cmd, target the upper union (evt_struct->iu.srp) instead, as that's what is being wiped. Cc: Tyrel Datwyler Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Kees Cook Acked-by: Martin K. Petersen Link: https://lore.kernel.org/lkml/yq135rzp79c.fsf@ca-mkp.ca.oracle.com Acked-by: Tyrel Datwyler Link: https://lore.kernel.org/lkml/6eae8434-e9a7-aa74-628b-b515b3695359@linux.ibm.com --- drivers/scsi/ibmvscsi/ibmvscsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c index e6a3eaaa57d9..3bd3a0124123 100644 --- a/drivers/scsi/ibmvscsi/ibmvscsi.c +++ b/drivers/scsi/ibmvscsi/ibmvscsi.c @@ -1055,8 +1055,9 @@ static int ibmvscsi_queuecommand_lck(struct scsi_cmnd *cmnd, return SCSI_MLQUEUE_HOST_BUSY; /* Set up the actual SRP IU */ + BUILD_BUG_ON(sizeof(evt_struct->iu.srp) != SRP_MAX_IU_LEN); + memset(&evt_struct->iu.srp, 0x00, sizeof(evt_struct->iu.srp)); srp_cmd = &evt_struct->iu.srp.cmd; - memset(srp_cmd, 0x00, SRP_MAX_IU_LEN); srp_cmd->opcode = SRP_CMD; memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb)); int_to_scsilun(lun, &srp_cmd->lun); -- 2.30.2