From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB1437C6C6 for ; Mon, 4 Mar 2024 23:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709593842; cv=none; b=SH1z60cQ438vO4KynERyB9z+tpWySlQPn4vdnY+/TTtojcwYiM17qYjXZMdEMICF6+6Od3PsvpSBo7vA6Dfv4gB5AyeaOosGAOG8pdljqqZlnw5JA1CUO6OszAsfMvXnvQT2YNspBqWVyx/BXq6/TSXTUl9aBxRfN0c7l/1W5Dk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709593842; c=relaxed/simple; bh=wMZzStv0WI94dHIupt/3qTiQCvxmwKcJlo5DxooTw+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ULKVTei3ei1psuHUUqTJWTDcEej9yXue8foJMh2zsWKAiyr7jDqRqwhxqO8MWP6/js6T3w7FXdHePtjZYw0SRa3VAm5dBoZjdYUXh/D1mTHj6mxT1tYL6kYT0Tc4Yh7UFoqfmKkUU4JX7Ij/AaczckBsjOlm/gnSEbwtpQ5l1/c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=M6LtdNGN; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="M6LtdNGN" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5cf2d73a183so4437035a12.1 for ; Mon, 04 Mar 2024 15:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709593840; x=1710198640; darn=lists.linux.dev; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9msUTwBa3XNDAwjjPAvGjEpS0Gd3hVi8Z81nRq0fsvc=; b=M6LtdNGNWsVYFIdhHSh+PnDUibj3M3A7UJS8G9y96XtujSRhDaHgh8rSS0EDQIS94C 7WRC9ZG6QB3bhY8tEw81JruQGGEybKpoQ+/uZC4I5eBug5FixVkz4/JlbQTXxoRxnQhq c5Cy50tokdCErTr61X4iODt4Gdru6l6RFb+kY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709593840; x=1710198640; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9msUTwBa3XNDAwjjPAvGjEpS0Gd3hVi8Z81nRq0fsvc=; b=sdwkG6TZUTvuBIPrTnEr0ay6u9bXAZq4zX2nU6dwMoH6/ACvS7/pQCvPyeFtk1X18c 0Tnc/PU3LNmb3wh3QYUJ0QiJsP5U59QFibKs35wIyvgMT+cD9+nQKwk0FMipKzJdkfu9 r94U5458fU9R49N6sR91mUfe1zh0JXmLKKhAVf2LoTV7ArdrJsgLMz3oX50ibw5hLKKr YAUMvDjvgcmkI0OSiJJXkvCWre12S53lfMwBms2Gxhxt+L8qizS8exBlv19wR8WvaYb7 xFzgiiPIaUJ8w26jps/th3lESwqYr8nxpaqWHZ9Ij4M2Mqtt93Tfx5e5o2rP+zcQNFg4 GlQw== X-Forwarded-Encrypted: i=1; AJvYcCXfOMC35eOqYo5SOBigJLPaypbb0QPRtxc1EjhDsgibL8JN0TQeM87ifEQ4wgVVv789WINpOHtO6OopDYx3S5xBBfshKm0EaY/taPuDJw== X-Gm-Message-State: AOJu0Yyqp0zaKdl2BnVPr4vWxp6VQWGxpLEQ8uKIJIzITngUdfcYZp6x 2f5271FIk5s+jYY9FNdZIoqZ+DvdFqLHBnWT0tPZlBuGuozl8Rqx4eYvGocnRw== X-Google-Smtp-Source: AGHT+IEbAr3Hucp75eD8JSPbmT5fSEjkHtUZ6q2D8D6DXvd41jaoEyXkI1zB44xifF8tsNHZEQjQpA== X-Received: by 2002:a17:90a:e548:b0:29b:1bc5:cfda with SMTP id ei8-20020a17090ae54800b0029b1bc5cfdamr1080411pjb.16.1709593840120; Mon, 04 Mar 2024 15:10:40 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id fa13-20020a17090af0cd00b00298f2ad430csm8380840pjb.0.2024.03.04.15.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 15:10:39 -0800 (PST) Date: Mon, 4 Mar 2024 15:10:39 -0800 From: Kees Cook To: Alex Elder Cc: Alex Elder , Viresh Kumar , Johan Hovold , Greg Kroah-Hartman , "Gustavo A . R . Silva" , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] greybus: Avoid fake flexible array for response data Message-ID: <202403041507.BEF59739@keescook> References: <20240304211940.it.083-kees@kernel.org> <1c5ab1e7-ac66-438c-bc49-0785810e9355@ieee.org> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1c5ab1e7-ac66-438c-bc49-0785810e9355@ieee.org> On Mon, Mar 04, 2024 at 04:45:11PM -0600, Alex Elder wrote: > On 3/4/24 3:19 PM, Kees Cook wrote: > > FORTIFY_SOURCE has been ignoring 0-sized destinations while the kernel > > code base has been converted to flexible arrays. In order to enforce > > the 0-sized destinations (e.g. with __counted_by), the remaining 0-sized > > destinations need to be handled. Instead of converting an empty struct > > into using a flexible array, just directly use a pointer without any > > additional indirection. Remove struct gb_bootrom_get_firmware_response > > and struct gb_fw_download_fetch_firmware_response. > > > > Signed-off-by: Kees Cook > > Thanks for adding the comments! This looks good to me. > > Reviewed-by: Alex Elder > > > > I want to call attention to a few other spots that should > get a little more attention--related directly to what you're > doing here. > > I noticed that the GB_CONTROL_TYPE_GET_MANIFEST response > structure also contains only a flexible array. It might > be good to add a similar comment in gb_interface_enable(), > above this line: > manifest = kmalloc(size, GFP_KERNEL); > The definition of the gb_control_get_manifest_response structure > could probably be replaced with a comment. > > > The response buffer for an I2C transfer consists only of incoming > data. There is already a comment in gb_i2c_operation_create() > that says this: > /* Response consists only of incoming data */ > The definition of the gb_i2c_transfer_response structure should > then go away, in favor of a comment saying this. > > The response buffer for a SPI transfer consists only of incoming > data. It is used three times in "driver/staging/greybus/spilib.c": > - calc_rx_xfer_size() subtracts the size of the response structure, > and that should be replaced by a comment (and the structure > definition should go away) > - gb_spi_decode_response() takes the response structure as an > argument. That could be replaced with a void pointer instead, > with a comment. > - gb_spi_transfer_one_message() is what passes the response buffer > to gb_spi_decode_response(), and could be adjusted to reflect > that the response consists only of data--rather than a struct > containing only a flexible array. > > > Kees: I'm *not* asking you to deal with these, I'm just mentioning > them to you. My comments above (without someone else confirming) > are not sufficient to dictate how to address these. Okay, thanks! Yeah, I took a look at struct gb_i2c_transfer_response and I think it might trip the memcpy checking too since it's zero sized, but it's on the source side, which isn't as strictly checked. I'll add a TODO item to track these, though. -Kees -- Kees Cook