Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 0AC584446C for ; Mon, 9 Oct 2023 22:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EOMd29C/" Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B161E0 for ; Mon, 9 Oct 2023 15:04:46 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-27758c8f579so2958254a91.0 for ; Mon, 09 Oct 2023 15:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696889086; x=1697493886; darn=vger.kernel.org; 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=OMGseJH3xVpjS3Dz1XvWa31fmlgKwg7+vZGsOfoEaiI=; b=EOMd29C/7PuKYL5m4fkQywhldbZ76H6cZ/Wp35HIHUM9CPVzHk+9CRR8ZRQ8OH2f/a z53yE489POmJJmfPNHJcyDLYBudpVrti6QUbsWHd5sl+rqrEamhfVdY9bme8J89TvunX g/olBL8ln0Q1S2bMDXaSBlMYKX05wEyOdEDPI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696889086; x=1697493886; 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=OMGseJH3xVpjS3Dz1XvWa31fmlgKwg7+vZGsOfoEaiI=; b=tGv5ml1saYm5DpI0mvs/eGrtiLO6YKTrpoIKdO0wbeToqkuT95ZVtXUXMIrBoKAJ7Q IyiF3pfLsVa82JyjZYdeRkEACYFBZSEX4c6uHHS1RTYud+yVmMvx+bTOcoO+ylyPgrT+ pKj1cmhiPUYTPQu00dyBdq6IbsoTaCxt58o+UCQifYpDPFq/AeMQDnq5s4DtHG5pkAcP sooANS8Fm029gbBs77wjACqhJohnjJ8NptdTic6KnADYA/ePDZFzYD8p53ZZCgU2JoMI Wmk23XVTnXkJngmG6eTtyrbg1WKENI8fgFXdTrk6WRwAwb4k+tDmf5243mo8242IG+rj /USQ== X-Gm-Message-State: AOJu0YwIe5dJvwxyZjMCLg+EegNzjW62nuSjEkV4f2cCONiiFyAS5euT J/dH8XO9LYpdKnXnMUhPXGXw26x1JFSmsP0qhNg= X-Google-Smtp-Source: AGHT+IFwi/Hx77Qov3jXx2LoubrzaSvq6vp4/lVzgPmZBiOZdmu2RVJwmuDRCsMOZxlgxrP9y1bTLA== X-Received: by 2002:a17:90a:9205:b0:267:f5d1:1dd3 with SMTP id m5-20020a17090a920500b00267f5d11dd3mr13172366pjo.11.1696889085748; Mon, 09 Oct 2023 15:04:45 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001bf6ea340b3sm10155489plf.116.2023.10.09.15.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 15:04:45 -0700 (PDT) Date: Mon, 9 Oct 2023 15:04:44 -0700 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Srinivas Kandagatla , Banajit Goswami , Andy Gross , Bjorn Andersson , Konrad Dybcio , alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] soc: qcom: apr: Add __counted_by for struct apr_rx_buf and use struct_size() Message-ID: <202310091504.0C46189372@keescook> References: Precedence: bulk X-Mailing-List: linux-hardening@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: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Mon, Oct 09, 2023 at 03:30:17PM -0600, Gustavo A. R. Silva wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for > array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > While there, use struct_size() helper, instead of the open-coded > version, to calculate the size for the allocation of the whole > flexible structure, including of course, the flexible-array member. > > This code was found with the help of Coccinelle, and audited and > fixed manually. > > Signed-off-by: Gustavo A. R. Silva Yup, looks right. Reviewed-by: Kees Cook -- Kees Cook