Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5487412pxv; Wed, 28 Jul 2021 11:57:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRrMAGSAouAn0Q+YPa3MbpH0cekfTZq15hk4mByWveTntFvXULjhZM1bN1TaLwqtilZdYX X-Received: by 2002:a17:907:ab0:: with SMTP id bz16mr848822ejc.33.1627498672401; Wed, 28 Jul 2021 11:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627498672; cv=none; d=google.com; s=arc-20160816; b=nhhytmOP34nHQ57HOg78paC+bbjK4KGDK9pgxNOkaw3XqCCUDZohgS5JDxUn31hYYq XQ21pgrwshmGRJ1sHPaQ3T9HfKiRmU1NKUCyItUpmu4eap3KP17RVEJt9pCyROsML/KW /e9MZNig4sH9bKHUavNcyeIvRiuF1rTLppdxw/kqYW/m1eOMtBDNm1r9LnA2/k5lcLiU M+pn2dDyqxtNukm8L0sSldyPr3Pt0e6rCTXn/OXpggNt6LR8P5PV9PlQgQ6+Xi/nMgRv tnnsDJHz2+6wvrA1fe6Z4C1AJ9PpzPqOHeL/AfEUg1uodywajy5T0oso2q67H3r5vYNc +zPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=127Od1Z5L5mrPERJlQTktPz34XXJuvOrvHqT3KKh12Q=; b=lsNwOL264RwXzIDxmDwnRiMlx8emmfe2jjMn1Z9A1q+n9ssycYZ7I6W3w7hu+PwLfT u+NPF5blnvHrYF6Ny3L66X1D1wmCjnid8hgXufzwFyYyxrYyEB3cTl6ImzqK8OtkpPQU 4Khj+vYZXBeqVipa6two41949EThRnEw2NEKDKOuTZs80QIhx6wNlzQkRdhx2O0VfWVJ IVkuiITYDo77GHhAkXYv4+Mp6+MdjcQflmUsNwxRpTKE1WaB4FezoGIF8PuOParVRKPb EhB0dYVawy8dCepBxihodhnb4fGnvLeldrCGm3sKMzqIMGl69ozJu361pHWpaz4NxGZ7 JrjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="CT/CUy6V"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 s7si604896eju.185.2021.07.28.11.57.28; Wed, 28 Jul 2021 11:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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="CT/CUy6V"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 S231282AbhG1S5U (ORCPT + 99 others); Wed, 28 Jul 2021 14:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbhG1S5T (ORCPT ); Wed, 28 Jul 2021 14:57:19 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF70C0613D3 for ; Wed, 28 Jul 2021 11:57:17 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o44-20020a17090a0a2fb0290176ca3e5a2fso5525744pjo.1 for ; Wed, 28 Jul 2021 11:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=127Od1Z5L5mrPERJlQTktPz34XXJuvOrvHqT3KKh12Q=; b=CT/CUy6V11s/6KhYMzSsdsMDErLudpJAHUqNC0Rpu9F7Ero2CNsiQemV80Kh7YxA18 O09bddDAkQD5N79FTWd2JhufucZWJdvUnGQK4C3MDdI6o+fliBhy2PpoYHcWAEFN4pot mlS6O/Te+d+/T7xLqqDiIN6UOLBL2XxRO5jCQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=127Od1Z5L5mrPERJlQTktPz34XXJuvOrvHqT3KKh12Q=; b=jGuzrsWSakkYsiYhHzqV/mikolss+OORxk+sPY9YJH0bUhlYQICQAL38/1Lmx6h97Y y/IYQdhvnquDK1KKhw+NxUrVzvS/hnDOrp4p/f3C2a01Z7/1XR8U0oHYOhFiyhq4Kz5M Uj8wksjQEk0+T6blfyBLAcwaQHNMQUZc5g7/bKPhN3MVLLX+yYLdWXiXk7nck8WyHhNo 21l2suyzEhRE88SG18knSASXlOsZphbIoKgtGtIgmAanrHSrtFwkJ5EzeNZc8Gdj2FHm aLLFkHBCSe28DPlfSajIwSBlwiA0rVgDQis5DTjwGtxIZ3emVw8nBoFY7zfZJQCiEWGq 7VpA== X-Gm-Message-State: AOAM533zwZTnjU6poa1uqdHWYnpjvV857YACAAVgz7WEukL5N14XEXjc t+d2k6NuKxM48sMLurbxLprhvg== X-Received: by 2002:a63:4c26:: with SMTP id z38mr313058pga.376.1627498636621; Wed, 28 Jul 2021 11:57:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d14sm5792859pjc.0.2021.07.28.11.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:57:16 -0700 (PDT) Date: Wed, 28 Jul 2021 11:57:15 -0700 From: Kees Cook To: "Martin K. Petersen" Cc: linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Keith Packard , Greg Kroah-Hartman , Andrew Morton , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, Brian King , Tyrel Datwyler Subject: Re: [PATCH 36/64] scsi: ibmvscsi: Avoid multi-field memset() overflow by aiming at srp Message-ID: <202107281152.515A3BA@keescook> References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-37-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Tue, Jul 27, 2021 at 09:39:39PM -0400, Martin K. Petersen wrote: > > Kees, > > > 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. > > > > Signed-off-by: Kees Cook > > Orthogonal to your change, it wasn't immediately obvious to me that > SRP_MAX_IU_LEN was the correct length to use for an srp_cmd. However, I > traversed the nested unions and it does look OK. Yeah, I had the same fun. Maybe I should add a BUILD_BUG_ON() here to help illustrate the relationship? I did that in a few other places where the equalities weren't very clear. For example, change it to: + 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); > > For good measure I copied Tyrel and Brian. > > Acked-by: Martin K. Petersen For the moment, I'll leave the patch as-is unless you prefer having the BUILD_BUG_ON(). :) Thanks! -Kees > > > --- > > drivers/scsi/ibmvscsi/ibmvscsi.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c > > index e6a3eaaa57d9..7e8beb42d2d3 100644 > > --- a/drivers/scsi/ibmvscsi/ibmvscsi.c > > +++ b/drivers/scsi/ibmvscsi/ibmvscsi.c > > @@ -1055,8 +1055,8 @@ static int ibmvscsi_queuecommand_lck(struct scsi_cmnd *cmnd, > > return SCSI_MLQUEUE_HOST_BUSY; > > > > /* Set up the actual SRP IU */ > > + memset(&evt_struct->iu.srp, 0x00, SRP_MAX_IU_LEN); > > 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); > > -- > Martin K. Petersen Oracle Linux Engineering -- Kees Cook