From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 30673442B3F for ; Mon, 10 Aug 2026 20:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786394493; cv=none; b=pB/sAwU4FTKe+ZOR8vtzRNxmskbiq8uTFEFKydFekYlKYurEjDrzEe7YVGE/79lblLiGGr1nvwhJRawkWz/ubCIPY4tK0hWawh9JbE9Qc3+fQcztiDFqL2v2qD0F6fyUUTwVlIK7ni+2YHXTVw2G8fSVIGaAlU4i5/+5p8j7VDA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786394493; c=relaxed/simple; bh=pFQD9MFc4A7vMMm3znX2ZQ/fMcPWFpch65waZMmi/CM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: Cc:Content-Type; b=fdxDAzisQyfwjr0KvOLPREU0a8ZGV81VWWKjSjo4UBLDeDb+OBueACpdUDqwNw3gUCg4ll2roweb2LVH2mGtBkjXjJ3W6Yo19Tc/o7d2nJc/z7tR5hiJ905Cbjij6ANR4o1YS4XohKM76f/a03oRkyDDme4jMER7XXCt4cXMdI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ix1jsaBp; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ix1jsaBp" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-385d2703b64so283374a91.1 for ; Mon, 10 Aug 2026 13:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786394491; x=1786999291; darn=vger.kernel.org; h=content-type:cc:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TEfuVEjGYGEogEAHeBDsRpCxcd7/D4XhwfU+1h+Q/ks=; b=ix1jsaBpWEe//RJdvGX7Lyiirw4HtQN2Ym/FEDxpBrxcJAuiRcUddZSSwgnMOLMjDX 8NJsrlNX71uJ1+d5SORB/KPATmtqow+q1+qkLDITGgHlGCZ4nTi9EI8DaabgxE+Z6TOO vw/d03PwXJ18oPJjD/NFZu8TGMR5kWhCzCubGcrOKiMaUTuJJKiPh17Cj41SwwgxMzs4 pFxIgLDI0raULDzYSYTdxepsQ5REf3icghHcEKXZ29g9/xM7mcU1MUmQecLOgwW47v8Q diUTm2KvHwx6RCdHqJ10NnbkDhR0YB3JNjd50HSDmDlUJC1zkO54iI8EY7dZsyp1bYw+ 8wag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786394491; x=1786999291; h=content-type:cc:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TEfuVEjGYGEogEAHeBDsRpCxcd7/D4XhwfU+1h+Q/ks=; b=bwQ6J5S9XDr/8Aw52JVXvZmh9XO/GCv8lX681MCzSlOGHiGcWtViYvaaZTzU74j9ck jTc92vx9m+EsK/2s7uaxLOm3iswYK7eir5AQrHs7OzJvuwkKHqKFJVB2Y2KYVALihhFI 1XHpyC9u8EMTHEmCURke7uMWmwzSYwu8exZEOOVdO4PcJoAkkqPdfEaabLVQYJXi4oVs 11KnmLLTjUmJ9sGVjE8v6hLtiqQgM0ESvHz90qwb9jehHGh1S8LfU6dBmZpBNrtFcayE +2tlVvBv/sYo+NUPDRYHoOgvu9w2f7b8WhcYeetOcyFdeFjJnd2PHPIegi/pViNs/cZn 2kyA== X-Forwarded-Encrypted: i=1; AHgh+Ro5Rvtc50udTpAPfG0On36iGUqirnqfAEUZjPz7sm+HhnbF28Ud4DBVT/0Zm3FuO9eNcSXNVRawfGxj3b4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywf5W0FIePJiWLElDich4Rdi9m3tDz1rb+NdLMsPUtjcAtMFtSn c8kuprJvrxuvrV8AJ1c3XajA6K3+t4oe9cuPRgZli4UdNoX+gMc+ZWUGMefqGBBpX+WLxfQNIO5 Z X-Received: from pjab15.prod.google.com ([2002:a17:90a:100f:b0:381:171e:961c]) (user=morbo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2d0e:b0:390:b3c5:e2c9 with SMTP id 98e67ed59e1d1-392d61cf225mr489608a91.17.1786394491093; Mon, 10 Aug 2026 13:41:31 -0700 (PDT) Date: Mon, 10 Aug 2026 20:41:12 +0000 In-Reply-To: <20260810204118.1981755-1-morbo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260810204118.1981755-1-morbo@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260810204118.1981755-2-morbo@google.com> Subject: [PATCH 1/2] vfs: Annotate struct fdtable's fd field with __counted_by_ptr From: Bill Wendling Cc: Bill Wendling , codemender-patching+linux@google.com, Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" The 'struct fdtable' holds the file descriptor table information, including the current file descriptor array 'fd' and its size 'max_fds'. To harden the kernel against out-of-bounds accesses, we can annotate the 'fd' pointer field with the '__counted_by_ptr' attribute, referencing 'max_fds'. The compiler uses the '__counted_by_ptr' attribute to track the size of the memory allocated for the pointer field, enabling runtime bounds checks under KASAN and fortified functions. There are three places where a 'struct fdtable' is initialized, and in all of them, 'max_fds' is set before the 'fd' pointer is accessed or assigned in all allocation and initialization places. No accesses to 'fd' occur before 'max_fds' is set, preventing any potential runtime false-positives or panics due to uninitialized count fields. This patch was generated by CodeMender and checked by submitter. Cc: codemender-patching+linux@google.com Signed-off-by: Bill Wendling --- Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Kees Cook Cc: "Gustavo A. R. Silva" Cc: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-hardening@vger.kernel.org --- include/linux/fdtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index c45306a9f007..3a5c88291125 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -25,7 +25,7 @@ struct fdtable { unsigned int max_fds; - struct file __rcu **fd; /* current fd array */ + struct file __rcu **fd __counted_by_ptr(max_fds); /* current fd array */ unsigned long *close_on_exec; unsigned long *open_fds; unsigned long *full_fds_bits; -- 2.55.0.679.g6767b8d81c-goog