From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 9B8CF132C04 for ; Thu, 25 Jan 2024 18:00:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205620; cv=none; b=EWmxVbCK60aiteX+Lya5jLuU9l5mu2m73QmpvHfbIi5RhzV3psZHKkfxXGpqGieFLgATHhKOSqsYmOYmC7NS2E+BY8Qke7GwCZ5MwKozc6GZ9MCU/jjj3BolPyNWkwML8xXotGxtwYUemQ0RsT1/CeQsujHtjPPmjbyM9cu1xrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205620; c=relaxed/simple; bh=mT3YLkbrBaeTvDcmwOHl1CS/WsjvlqLYlUMs+sUIjqo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MoxVc/pa4zdpFzYdtstidrTzJNlUtIC8cFZa8emHnKw4KmiuWcV7lOv6U8z0RsB9s0/5m3qSdQE2/daBL9t78qYTfwDe1O8XM0z7oN3P2b3PBCoyeD1IOH1LdzshCL0PfhzB1dl6DF+hQpPy8cA0cC5/MI18xJ6MNt5lGeSwgXs= 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=XhE/jQTu; arc=none smtp.client-ip=209.85.166.170 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="XhE/jQTu" Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-362a24b13e6so3653595ab.2 for ; Thu, 25 Jan 2024 10:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706205618; x=1706810418; 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=ASf7ytaMtxVk0xSdSw9HpPo51B0EyC7CmU5TJyjG/94=; b=XhE/jQTuPDMrQl3r6qt9dk0jAM3nry0KX/S3wXKPTDr4Y2qBf1yX+GvDeJ0h1Whz8x lTufBDnZUwWba6cJQxJHhzMEIgGm346aN54ztvqAiZtbA1+whLSFcmbzihbsSWo0c6A0 HovTe5pW/7BZ+tqzBlL4kkQU8cs0m6GzWsIGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706205618; x=1706810418; 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=ASf7ytaMtxVk0xSdSw9HpPo51B0EyC7CmU5TJyjG/94=; b=iZIJmZxo0BFpOXVNzpZaPfHadMSfrhvaouZyCZGIakM/GW8+RyuLVFjPZEOeyrJmzR gTBSC8homT44tsCaeRQE1fXjXRKnEyA3trL02kdA54Dw6PdT6HG/clAVJMkQZ0veJotL oJem6XZTluJpKcsBhnWiyYiCbY24iA9zb4DDxeFdVye3NYTzMELOy0cYm9Dqq+LQJvB1 FOn6VrxzC24RmqITEdDuPaxTxzhFJDzXuUQ1rnW/cPT7sq4KpiXD5kipAh5jkj5xXMFc 0F4gdcmoEmrziq7McvN1ljJZjFvyesCxr+RrFTFHHIwrtrkSz7/Mm/LWgitaiEFaMZLa J04w== X-Gm-Message-State: AOJu0YwXrrzz378y+5p0/fY4uiIAdZRRp4IAk9kFCcZ9Beoe+g1VMhgC lHyac6jNqCYqn/EI83Ug6KyMLEmR/0aRIu3tfWbNvXGpYeEDlZseVgZV5f0WYw== X-Google-Smtp-Source: AGHT+IGPddlDJxd6qVGArdVFf9Nrta2FGnNCUo/WGULBp9ke0+atvbxuIdfHfuqucOPAMPk2QtvD5Q== X-Received: by 2002:a05:6e02:1a6e:b0:35f:ef30:d665 with SMTP id w14-20020a056e021a6e00b0035fef30d665mr115219ilv.41.1706205617791; Thu, 25 Jan 2024 10:00:17 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id 73-20020a63004c000000b005cd835182c5sm13721878pga.79.2024.01.25.10.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 10:00:17 -0800 (PST) Date: Thu, 25 Jan 2024 10:00:16 -0800 From: Kees Cook To: Ard Biesheuvel Cc: Steve French , Nathan Chancellor , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , linux-cifs@vger.kernel.org, llvm@lists.linux.dev, Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] smb: Work around Clang __bdos() type confusion Message-ID: <202401250958.11B29BE48@keescook> References: <20240123234731.work.358-kees@kernel.org> Precedence: bulk X-Mailing-List: llvm@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: On Thu, Jan 25, 2024 at 01:19:19PM +0100, Ard Biesheuvel wrote: > On Wed, 24 Jan 2024 at 00:47, Kees Cook wrote: > > > > Recent versions of Clang gets confused about the possible size of the > > "user" allocation, and CONFIG_FORTIFY_SOURCE ends up emitting a > > warning[1]: > > > > repro.c:126:4: warning: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning] > > 126 | __write_overflow_field(p_size_field, size); > > | ^ > > > > for this memset(): > > > > int len; > > __le16 *user; > > ... > > len = ses->user_name ? strlen(ses->user_name) : 0; > > user = kmalloc(2 + (len * 2), GFP_KERNEL); > > ... > > if (len) { > > ... > > } else { > > memset(user, '\0', 2); > > } > > > > While Clang works on this bug[2], switch to using a direct assignment, > > which avoids memset() entirely which both simplifies the code and silences > > the false positive warning. (Making "len" size_t also silences the > > warning, but the direct assignment seems better.) > > > > Reported-by: Nathan Chancellor > > Closes: https://github.com/ClangBuiltLinux/linux/issues/1966 [1] > > Link: https://github.com/llvm/llvm-project/issues/77813 [2] > > Cc: Steve French > > Cc: Paulo Alcantara > > Cc: Ronnie Sahlberg > > Cc: Shyam Prasad N > > Cc: Tom Talpey > > Cc: linux-cifs@vger.kernel.org > > Cc: llvm@lists.linux.dev > > Signed-off-by: Kees Cook > > --- > > fs/smb/client/cifsencrypt.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/smb/client/cifsencrypt.c b/fs/smb/client/cifsencrypt.c > > index ef4c2e3c9fa6..6322f0f68a17 100644 > > --- a/fs/smb/client/cifsencrypt.c > > +++ b/fs/smb/client/cifsencrypt.c > > @@ -572,7 +572,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, > > len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp); > > UniStrupr(user); > > } else { > > - memset(user, '\0', 2); > > + *(u16 *)user = 0; > > Is 'user' guaranteed to be 16-bit aligned? It's the first two bytes of a kmalloced address range, which I'm nearly certain will be sanely aligned, as those allocs are commonly used for holding structs, etc. -Kees -- Kees Cook