Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp204966lqb; Thu, 23 May 2024 15:48:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmsxEdhoWZVXZdFDARSsh6JxtfOD+jB+bhRzidJxvld3vB7M6SOpGosXh/aF43jPKPVluBiuttlWwzLfDsc+tpPhslgCSYkvoqkLKI4A== X-Google-Smtp-Source: AGHT+IFiuG/FfStT8RTOvNxuizP7LzDouIvOaH08qHs4aX1BiANX6oilUdmbeR2e1KxXFaI6qpR9 X-Received: by 2002:a17:906:40d8:b0:a59:c833:d275 with SMTP id a640c23a62f3a-a62642df815mr36666466b.30.1716504508983; Thu, 23 May 2024 15:48:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716504508; cv=pass; d=google.com; s=arc-20160816; b=mO9Qw6aEJ/JjROujocLbBzCfFCT7hbziYRcg6uTyI/Wsrf8hGgLNlttzYHM5ZjdbaU AeZyXY4TnASe98YeXMm9E0d0zPz1WmBRYVYjxs1Ekht0rmlsDp4TU3MAyO1Ntdp0JhH5 ds3z+cwr+3J2k7lYLBTXHqc/w0eIwZ8igiIlZI6NJYvsQ214pnqJMtR/4DLZ56HQd1Yq Hht8UxDIzweJcbPLo4NFuuw4TLezTGFXxwRXOVWIsVqz39D4gAzoY2J0dEWtPkhZGTqp zodCUMwVVrmUk+WdduWuO6F63YHvO+IBrA8twJIrWQvOwGkK3Jkzn+EYpM5ve+DqQhK/ Zn/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EA4oat8jyy3CDEKkZfrcdIUDv0o+HLO5NbY98ff+pUo=; fh=mF4bf6SKsZu6Xwhsmv7HVA7L0zMgmD1qNM94MQ9nHR0=; b=IRGc28gUZN0rjwSM7NkpaPgHBMh2ri8uTO57UjjZFnX5hVArv8ciCJk91Zue6iBFSV 5mxlB0IxKYeQxALmdeZSWWtEWmKPceOOEt/VZxxFPKKtL9iQKh411ePk73UzQKwFBs8j xONBTDPHeRQzFWf0Lm0kzYuvcZuGAal+Iaf3Cr4FLvxB7lIPZ0wzqRhvkSSmdsyN1oK8 pOvJobz5YVMb/jd417EhPOaCmFwt6ELweJWHhsgZsWh3PcKGCT/xnYU8dOemFnU/bpH0 0DIUQWFH+b3NQB0C1li0FsLpx/gEksrpECnjtsJxn6kznYKgQcPFjZOB+o3uirG+NmZu bUzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=U57Sh1V8; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-188087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc68f31si12597766b.627.2024.05.23.15.48.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 15:48:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=U57Sh1V8; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-188087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B3C001F22BD4 for ; Thu, 23 May 2024 22:48:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0EBC12880D; Thu, 23 May 2024 22:48:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U57Sh1V8" Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 73D81128812 for ; Thu, 23 May 2024 22:48:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716504484; cv=none; b=GqzVlt3k+MPStQsx0BUEWE9cn9lNYw3iaSdUx3qPfY4F4M4e6lbXjE0fkf+nRar8veMkPzuX4Us+e24ZAAC+sb1efBeIh/kOTLoJ5JOMNiaMcQcfs5q/FaolHin4S+5CgWmvbyECdOLGYa/BA3TFD38DMcoR+tvFAvYv8VAK3O4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716504484; c=relaxed/simple; bh=gz0PkwjZapZ313UpBb/0ZCcYeCPvCTVsQ+dYKgCkRYI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AdYQoyY6GlJOEsU8QV+7kpdnsoWkLc4aOgT+uB1amZiw51HfBI8miMwOwsmk7oFNA2ay75XVHnBGeeNpdyBizpeXs0GJ4sm0EZO/eSPEyJBGuOzsrAvKwukJK7Qmbwa8RZW1k/4ulsZeP5B17uwGgrmFgLfiEuTttn+XlOp9jTg= 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=U57Sh1V8; arc=none smtp.client-ip=209.85.214.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 Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f3434c36baso8787205ad.2 for ; Thu, 23 May 2024 15:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716504483; x=1717109283; 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=EA4oat8jyy3CDEKkZfrcdIUDv0o+HLO5NbY98ff+pUo=; b=U57Sh1V8YyODu9+AZPf+p+WnEA3anP4y64iyy/fes3u3L+Wcj81oCO8RFSj+/5Ae5F qxgbajzWSaQ7GstdM6AJ5MEbkOO2YKYeo8HvJN+JnPwyPROuYHy2bN2vPY5V4/Xuf4Zd BXTdKE690HlAerrTp56EUkJ0l5dUyrNgfDMxg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716504483; x=1717109283; 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=EA4oat8jyy3CDEKkZfrcdIUDv0o+HLO5NbY98ff+pUo=; b=DMC7yLpsDn1VdMrXDmCays/TlFJxLYJtY6w0zhSSabdrg3imvXew76MELyeqEiJba2 pB2hdAwTJydHlPEowst5/HZzQ6kS8HJGJUK94rZwZ3PRv0DW3ks9VMoPPgVfR0UxYtZl BDxQS+wjdZpS6Jj7TLjfUvusFJ3BNheAk51n/K6/cNHgCIFwGPCQHMERH7AQmsF+Wccc atnfDKW9exdbRioVXRpK9bxZEtE4stbVRyqHxAHj6O6SJ3iWm4dXDwgtVIFMIOA8VhIh HUbVubNcJjZnD4BP2O9dVErQCcRGrJjwUdcaP/fpPvHOint2WpUvOi0E4wyi1kQKxmQI 1/ZQ== X-Forwarded-Encrypted: i=1; AJvYcCWCeNX7u5RjWFLZRHGKWIM1BZ9fFte2ScKqyuvnGgw4HBCT9pXyZ5nJ6I6vHEHO466qt7kJoLMRUnJKvA/blDN/ckh9eP8wsujTTeJN X-Gm-Message-State: AOJu0YxDMa0d6f1nRHBEnlpK8gOyfKmM6B78QUSQi1vVDZm2HO5lRsKd iVeEDj26y143+/FFbpLtfh5A/CE+AUQ618V8PLYdorSw31zGn8hECU7dpXvAlQ== X-Received: by 2002:a17:902:cecd:b0:1f3:35e8:d309 with SMTP id d9443c01a7336-1f4486d9f35mr8074405ad.20.1716504482757; Thu, 23 May 2024 15:48:02 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c9aa1f1sm942125ad.241.2024.05.23.15.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 15:48:02 -0700 (PDT) Date: Thu, 23 May 2024 15:48:01 -0700 From: Kees Cook To: Theodore Ts'o Cc: syzbot , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Justin Stitt Subject: Re: [syzbot] [ext4?] WARNING in __fortify_report Message-ID: <202405231540.84B3DBE841@keescook> References: <00000000000019f4c00619192c05@google.com> <20240523130456.GH65648@mit.edu> Precedence: bulk X-Mailing-List: linux-kernel@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: <20240523130456.GH65648@mit.edu> On Thu, May 23, 2024 at 09:04:56AM -0400, Theodore Ts'o wrote: > On Wed, May 22, 2024 at 11:29:25PM -0700, syzbot wrote: > > Hello, > > > > syzbot found the following issue on: > > > > dashboard link: https://syzkaller.appspot.com/bug?extid=50835f73143cc2905b9e > > > ... > > strnlen: detected buffer overflow: 17 byte read of buffer size 16 > > [<8080fe10>] (__fortify_report) from [<818e9a40>] (__fortify_panic+0x10/0x14 lib/string_helpers.c:1036) > > [<818e9a30>] (__fortify_panic) from [<8062a3b0>] (strnlen include/linux/fortify-string.h:221 [inline]) > > [<818e9a30>] (__fortify_panic) from [<8062a3b0>] (sized_strscpy include/linux/fortify-string.h:295 [inline]) > > [<818e9a30>] (__fortify_panic) from [<8062a3b0>] (ext4_ioctl_getlabel fs/ext4/ioctl.c:1154 [inline]) > > > [<818e9a30>] (__fortify_panic) from [<8062a3b0>] (ext4_fileattr_get+0x0/0x78 fs/ext4/ioctl.c:1609) > > [<8062829c>] (__ext4_ioctl) from [<8062aaac>] (ext4_ioctl+0x10/0x14 fs/ext4/ioctl.c:1626) > > r10:836e6c00 r9:00000005 r8:845e7900 r7:00000000 r6:845e7900 r5:00000000 > > This is caused by commit 744a56389f73 ("ext4: replace deprecated > strncpy with alternatives") and it's unclear whether this is being > caused by a buggy implementation of strscpy_pad(), or a buggy fortify, > but a simple way to fix is to go back to the good-old strncpy(), which > is perfectly safe, and perfectly secure. > > (And this is a great example of "security initiatives" being an > exercise in pain alocation tradeoffs between overworked maintainers > and security teams... regardless of whether the bug is in fortify, > syzkaller, or an effort to completely convert away from strncpy() > because it makes security analysis easier.) It looks like this is another case of a non-terminated string being made terminated by strncpy into a string with 1 extra byte at the end: char label[EXT4_LABEL_MAX + 1]; ... - memset(label, 0, sizeof(label)); lock_buffer(sbi->s_sbh); - strncpy(label, sbi->s_es->s_volume_name, EXT4_LABEL_MAX); + strscpy_pad(label, sbi->s_es->s_volume_name); unlock_buffer(sbi->s_sbh); This should be using memtostr_pad() as: memtostr_pad(label, sbi->s_es->s_volume_name); I'll send a patch. It looks like __nonstring markings from commit 072ebb3bffe6 ("ext4: add nonstring annotations to ext4.h") were incomplete. -Kees -- Kees Cook