From patchwork Wed Dec 4 19:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 847316 Delivered-To: patch@linaro.org Received: by 2002:a5d:434d:0:b0:385:e875:8a9e with SMTP id u13csp513426wrr; Wed, 4 Dec 2024 11:51:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUGB+q9ERB4PbU8dYT8vaV4cm4HLxtfTJYLPLhFZFSh0kc/CBJVPNigkDDNyqkztqo18huOSA==@linaro.org X-Google-Smtp-Source: AGHT+IGclmFpixHDVRRuZtD4Nm7au4jsUNI4YWhslYRfVMGZKwxubsVq+HR0VPz/2ByVVk6936DS X-Received: by 2002:a05:620a:628b:b0:7b6:91a4:845b with SMTP id af79cd13be357-7b6abad90famr842263785a.15.1733341917537; Wed, 04 Dec 2024 11:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733341917; cv=none; d=google.com; s=arc-20240605; b=gze3fX9eFEgnQV2mzpU6Ag2UnsBHJ7CHHxtZY/68VJUrIOkKVUmxwaaTf+qZ94+Vy+ Mkj5P6wmD/dvS1+7MCbt46pT82wzTRHH3PXmx+PzaPKn8IM+QQCB0sGXGSPfyTQuUJoj S8RcQ4D9mLpFCeCX3d4RfNMLdYtOEZAceGbzzRAu6gwkUgIG2d7oo5jGMYdZ7LmTspol nt3Iyw9Zxvzke3Foji1J9+FGC72GwnrnQppjvQV90urMHYoqBkpexXkBY7ltJMTbdJo1 vyxOjK0tOoIu+bxSDINTkHOtMFrmvjo1m19gZ8HT1phWAJsSxFLJwb25WiWfIQYyOgce gZnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=hJnVqGKgE5xAxt3ubjaUh4ERJ027DT3bfz1Npiam3ec=; fh=DT0vjF4AaAGXBixd3lXYKfQ8oTDSxfG0q2aimKpnZGg=; b=iQ4hg0CizOfSZHzYFP9WlTaDvKVBcN0q2JbYcQfQpeWmHEyMPNiiEdT00ACyLM0Qjw IicZ+3NRqvjNTXXe4queRyTBRVNe2/gW+cQobNbarHT0j1kjaOU5gu+M7pJG+HUY+Ffd L1/7K6iWbptRTc/ulZr2l8l0/295NhCuP+MNDowHAH+gGGznJSNOL7POiG2tPPk/l+ZH bXvo+dQKczULSmAa4OVZLBz08i43DWuh3h7NUKtm7V7AzGgbIWPfGAdEcDe6vB682zKG 83vPuTpyFIf2Ep7nIl8NGzj94c7aDTHY5vvGVZblina0AzxQD+F7czCybVD41MpViAD0 L10Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fQUmkMwS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-466c40555b7si168926661cf.89.2024.12.04.11.51.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Dec 2024 11:51:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fQUmkMwS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIvPN-0000ws-Jd; Wed, 04 Dec 2024 14:51:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIvPL-0000vY-Hg for qemu-devel@nongnu.org; Wed, 04 Dec 2024 14:51:35 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIvPJ-0001Jb-Pt for qemu-devel@nongnu.org; Wed, 04 Dec 2024 14:51:35 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-215bb7bb9f9so919945ad.2 for ; Wed, 04 Dec 2024 11:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733341892; x=1733946692; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hJnVqGKgE5xAxt3ubjaUh4ERJ027DT3bfz1Npiam3ec=; b=fQUmkMwSH9A0zRy6igpDPcE8Bhu0o+MkAgnw0fEWDXaZj+Z17SgJwsPPrFaPNTcNjY 1xAjYV7SR3HmVbG72/XX6HiaRK0Hg9Te8IYcZyNu9wkO0G0DAamrmqNs1gEL8zQE6Mdd Qi04YRBFANa43KHKCCh48bJHzh52wOiuUnCq4wjVNAjTV/MxK0pXXwqD+qL11BMNCx9j U8GEg8bCMrd2gUQDfluhytDKSW5ffGOCXWBJcYdvzJDGtCSexotyw2zsI86w2uRViCmf rBmH1wKL0Iqyw5b+qg2gl8APn9s9owaLFII1+Pmmq9HzNNm0cYAX4PRJkVjURAcjxH88 aN6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733341892; x=1733946692; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hJnVqGKgE5xAxt3ubjaUh4ERJ027DT3bfz1Npiam3ec=; b=KrHO6ZOYqVO+hBrElorl4vPDhVj2EUI1kSoqfupSHbEQr+zXVYN0n2No44K5h3XsRU rTcWveuyjVZ4cRjNbO+nnvYyXU4xChganD0S3g6DIHCzoAtOOeoGd920dNq1+oR6OOu7 U3VwNdA9SprPIGpBywZSDecrcjeYfpEa7NRFd3KvTOIAuJPtA7aXva24bnvVCN30ZjVa F8Ncue6ud0tEHPFAqaxCCj9/n5m93oY9rEJOpKkZruevuun1JnhTzYNYtzR9TpBnhuFt nPF4waSAtTkNgNEpD6nd+5wUGgtpuVb276Oi8nV2ipnN4mUQ0oAQArXwV20Sy5ePgqOe sc/w== X-Gm-Message-State: AOJu0YzmQIi9m0mVPT4N5AJCWe4hAg59t+MKLQARGA/yF7FG3U3idsFl +qu42pOnVQVNncWlBwYxj6WiZEZ8Qz/4o+AujFmj1YBtE9QwAKiQRn3hYZ0UR8w2+u5ijKM+5Nl fc7s= X-Gm-Gg: ASbGnctcSgx/z9cd8HpZmg6IIqA9CtN8XouOvIMZQ0JZ7HUQktGr3sqBj0eTm3+ZWhL EoIc+cuGIxONcMN7VCmRrzadDv/eRt2EN2fFAINE/cjFEaV7YCh/MLEBAqxGegeOddnLC6W+Qig MLpXs1ZE9TYkCrZyWKIJVpV7Qf9oWm8K1OdnicfwkVTVRwghP5WBIO5POp7rogi+jwCPCedVO/4 pSCi/Aoj4Ky8x+oW/v52QJlfVxfdSAtTtF1s52xjtjltHZqSDwqbnmvnsWerUF2ubHmMX2qevXE 2etjZm8D X-Received: by 2002:a17:902:e744:b0:20c:5533:36da with SMTP id d9443c01a7336-215d00b8806mr81359925ad.42.1733341891825; Wed, 04 Dec 2024 11:51:31 -0800 (PST) Received: from pc.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725417fb950sm13162824b3a.121.2024.12.04.11.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 11:51:31 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, alex.bennee@linaro.org, Kevin Wolf , Hanna Reitz , peter.maydell@linaro.org, Pierrick Bouvier Subject: [PATCH] vvfat: fix ubsan issue in create_long_filename Date: Wed, 4 Dec 2024 11:51:11 -0800 Message-Id: <20241204195111.2921141-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Found with test sbsaref introduced in [1]. [1] https://patchew.org/QEMU/20241203213629.2482806-1-pierrick.bouvier@linaro.org/ ../block/vvfat.c:433:24: runtime error: index 14 out of bounds for type 'uint8_t [11]' #0 0x56151a66b93a in create_long_filename ../block/vvfat.c:433 #1 0x56151a66f3d7 in create_short_and_long_name ../block/vvfat.c:725 #2 0x56151a670403 in read_directory ../block/vvfat.c:804 #3 0x56151a674432 in init_directories ../block/vvfat.c:964 #4 0x56151a67867b in vvfat_open ../block/vvfat.c:1258 #5 0x56151a3b8e19 in bdrv_open_driver ../block.c:1660 #6 0x56151a3bb666 in bdrv_open_common ../block.c:1985 #7 0x56151a3cadb9 in bdrv_open_inherit ../block.c:4153 #8 0x56151a3c8850 in bdrv_open_child_bs ../block.c:3731 #9 0x56151a3ca832 in bdrv_open_inherit ../block.c:4098 #10 0x56151a3cbe40 in bdrv_open ../block.c:4248 #11 0x56151a46344f in blk_new_open ../block/block-backend.c:457 #12 0x56151a388bd9 in blockdev_init ../blockdev.c:612 #13 0x56151a38ab2d in drive_new ../blockdev.c:1006 #14 0x5615190fca41 in drive_init_func ../system/vl.c:649 #15 0x56151aa796dd in qemu_opts_foreach ../util/qemu-option.c:1135 #16 0x5615190fd2b6 in configure_blockdev ../system/vl.c:708 #17 0x56151910a307 in qemu_create_early_backends ../system/vl.c:2004 #18 0x561519113fcf in qemu_init ../system/vl.c:3685 #19 0x56151a7e438e in main ../system/main.c:47 #20 0x7f72d1a46249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 #21 0x7f72d1a46304 in __libc_start_main_impl ../csu/libc-start.c:360 #22 0x561517e98510 in _start (/home/user/.work/qemu/build/qemu-system-aarch64+0x3b9b510) The offset used can easily go beyond entry->name size. It's probably a bug, but I don't have the time to dive into vfat specifics for now. This change solves the ubsan issue, and is functionally equivalent, as anything written past the entry->name array would not be read anyway. Signed-off-by: Pierrick Bouvier --- block/vvfat.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/vvfat.c b/block/vvfat.c index 8ffe8b3b9bf..f2eafaa9234 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -426,6 +426,10 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) else if(offset<22) offset=14+offset-10; else offset=28+offset-22; entry=array_get(&(s->directory),s->directory.next-1-(i/26)); + /* ensure we don't write anything past entry->name */ + if (offset >= sizeof(entry->name)) { + continue; + } if (i >= 2 * length + 2) { entry->name[offset] = 0xff; } else if (i % 2 == 0) {