From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74FB1CD612F for ; Mon, 9 Oct 2023 19:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378486AbjJITxF (ORCPT ); Mon, 9 Oct 2023 15:53:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378494AbjJITxE (ORCPT ); Mon, 9 Oct 2023 15:53:04 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25747E1 for ; Mon, 9 Oct 2023 12:53:00 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c63164a2b6so43536235ad.0 for ; Mon, 09 Oct 2023 12:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696881179; x=1697485979; 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=csxmouwm4ofhF5cKOMzE27Rri8PFeo+HUVsFVEvzccY=; b=Hz72/ybIP9jC9mxMUf4UTw0Bz5TIm09QLh8Oderyl/tI5IWU7LmDFO23VtiM40zZ3a 6x0xU4XZzONefqEbO4hFd2eXBLLN41vgGbTWirfGxbTZ9YaiH9PSihBY0con9XQsHMPa UbKwdi+elRJS4YyddjSuj+pNpyfB+JruVO8x4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696881179; x=1697485979; 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=csxmouwm4ofhF5cKOMzE27Rri8PFeo+HUVsFVEvzccY=; b=N1E8yjqFWzMfF31DmqiOlyTtNTKBDjtPQgg5VLVrmd3+FUJ9NixkQlGV6eM9vmrbGR 2/y8q9MjXTY+tmQxLN/Il9P8r4XvEdvH431anIDywdjhkny/jMPmGSdUyy8lDNAjUICJ xkpRudBiFdtyh7UcP2H4y2cld04OzK5AlR3CX5QHuT5LoVIGhYo6jkcxXWkyhwjkWXz9 ShlNeQ+YDoi6Ei5ULw8Sfo7kOrLd7DT3Buh2X7amYWchFsDiwAD9CnW5a/CHbwlbt51+ Chmr8qfxbAPfkxjQpu2fWQXQdAu6hU4rcP9nlF7rxJ6jlc3rFVMOx8PsiA7KX5MR9yD3 mIGQ== X-Gm-Message-State: AOJu0YzCCYrc9R+BIXn+F8Y7U0XQR3DCaswGNNhv3iOLpKLOtIfbPAsp nAY6AhAUXOX6Gd6lkwmpw2MHkw== X-Google-Smtp-Source: AGHT+IH8+Ntc+mkBfEJvhkMQnUhAYyhOXnvDI9W+fGYDOJ7tdwlzxtrOGtqb7aH6TTdMvZXTN2zj5Q== X-Received: by 2002:a17:902:c404:b0:1c9:9fa6:ce5b with SMTP id k4-20020a170902c40400b001c99fa6ce5bmr4306363plk.16.1696881179581; Mon, 09 Oct 2023 12:52:59 -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 t5-20020a170902e84500b001c3f7fd1ef7sm10043902plg.12.2023.10.09.12.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:52:58 -0700 (PDT) Date: Mon, 9 Oct 2023 12:52:57 -0700 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Andy Gross , Bjorn Andersson , Konrad Dybcio , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] media: venus: hfi_cmds: Replace one-element array with flex-array member and use __counted_by Message-ID: <202310091252.660CFA9@keescook> References: 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-arm-msm@vger.kernel.org On Mon, Oct 09, 2023 at 12:42:05PM -0600, Gustavo A. R. Silva wrote: > Array `data` in `struct hfi_sfr` is being used as a fake flexible array > at run-time: > > drivers/media/platform/qcom/venus/hfi_venus.c: > 1033 p = memchr(sfr->data, '\0', sfr->buf_size); > 1034 /* > 1035 * SFR isn't guaranteed to be NULL terminated since SYS_ERROR indicates > 1036 * that Venus is in the process of crashing. > 1037 */ > 1038 if (!p) > 1039 sfr->data[sfr->buf_size - 1] = '\0'; > 1040 > 1041 dev_err_ratelimited(dev, "SFR message from FW: %s\n", sfr->data); > > Fake flexible arrays are deprecated, and should be replaced by > flexible-array members. So, replace one-element array with a > flexible-array member in `struct hfi_sfr`. > > While there, also annotate array `data` with __counted_by() to 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). > > This results in no differences in binary output. Thanks for checking! > > This issue was found with the help of Coccinelle, and audited and fixed > manually. > > Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook -- Kees Cook