Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp189392lqo; Tue, 7 May 2024 17:19:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/y3467eWTpjT3JUAzfYZtz8vp/TlOAhGteQkWVtnkT+dwXicoun0IUV+06cTd0EFUgBWhSKZgySw7H/pY34y377KE+AcAhAAkOBHA6g== X-Google-Smtp-Source: AGHT+IG+Atb8o5LNW6jDkj/wr8S2B2P1rDnlixvBBZ89pyQUBQ4TToekUHDVE3fVAWHAvEXWca8z X-Received: by 2002:a62:f906:0:b0:6ed:416d:f7c with SMTP id d2e1a72fcca58-6f49c1e5c03mr1378518b3a.6.1715127557349; Tue, 07 May 2024 17:19:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715127557; cv=pass; d=google.com; s=arc-20160816; b=tTOkj8FkSLs9YFD1dBmfmFU20IAThv0+N0DwX65sYnQYq6QxNKLqPRzW3UVkeJKQw1 GiwWKxxv43hSX+M0B/j5F4/5ExrZEVRF8dgeqLZbGNftCsreRF+N1Z5QJ3BLAHlVYoXO 2KXs24DM7cfd6OeVNoD56AD+SI8Zr/lQtjlDeaqeXR/QzE7sfl+7hVlWgg+QgfiCAZKF HJEzFTtybp/ZuIPfXNF4lsmJU5FkkaGFOR9iMz/yuu7yb6FYpQE7RguHRlI4zoNOggsV GWJZQJHKjqYtuSdQrzLwBLGGeNs43qmrRMDsbiT8qAHMDNy7nkA2WPB4pNAGenWTNGPo bxug== 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=y1syOJovW5eId25dp/lIC5NMYcXKMWcKV21Z0vOpfbA=; fh=IWnQSG2mpS4R13gav3p2F6nmD98K/CHxZAGNnk3L6+o=; b=qXERW4CUzQiXtqLbKDazk2YhYSmtgnET5/vJp6ZvXwHFJdCoJHRcDtOXGakwFOCD0b EgwDJJ5ukjM5xZsuZIPuVfg8mfrKPQqhn8psrbAwzuBD1q58bOTCtbzW5Cab/IdT9kWb Vv5sKTHt8co7rVbOswL58M0G5/M2NYX8aqbJ7xnDr5VzIYMijLJgn+YgYChW1jsA0mDy QxEM6EMEaKrsULZhcdPf32sx3Yr145nBP5eYnSSRImNlB/eKOL+dRxTCjb+CzV1/hDM6 Kl6HeqKWwDga+5T2PXOAI8swYNUb75fryUCUIzTdSqTrudNtI5jZPQpr0VB/QA0XDSJM ziFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P3BpdlBR; 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-172543-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x3-20020a654543000000b005f3ffb0b152si10554696pgr.236.2024.05.07.17.19.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 17:19:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172543-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P3BpdlBR; 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-172543-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172543-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7F13D28B87D for ; Wed, 8 May 2024 00:11:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D88AC15D; Wed, 8 May 2024 00:09:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P3BpdlBR" Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 342A91C27 for ; Wed, 8 May 2024 00:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715126967; cv=none; b=f8hpi0Veoc5f7Wlmkgh+4Hk2CYNdE/AGBp4Vp48kS5L8eVa1qROv/Gz6cZInUCkn9Ar7bOHH54dv5LWc5oz9TpuWC1Pjb/xa2ZZqHev04Q8nVkQKmbCP73szVGhplO3tdq4xSeUAiYqsNYkicc8h/g3YRwlMQn9u6DtXY+1DZ04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715126967; c=relaxed/simple; bh=2RBkzmRwSheKgkAQe2JV3Fs7F/JeQq/TzY2YuKFXwgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YOchG5t5o4rpffFVSwE+K137K4k9lV5DdHdLnGyoPdDrj7dMhpiWAT4ONYV91t8R1irKxWNwW9JgpsmP6VFD6DHYfx34Suc6qbfk6HfNohLt37WNuJVrzq6iiml0Ja78onbLIiqlBIPeGlGyVBdAxPoFGzRAMXj9rPqDK0KgHEI= 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=P3BpdlBR; arc=none smtp.client-ip=209.85.216.51 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-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ad8fb779d2so2858720a91.0 for ; Tue, 07 May 2024 17:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715126965; x=1715731765; 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=y1syOJovW5eId25dp/lIC5NMYcXKMWcKV21Z0vOpfbA=; b=P3BpdlBRRYrhG9RwRG98tPisRxHqA9/nXL5OVnH/XDndDAqVIgGLLYrb23uF0xFmGC JYjuiUVsD6tEHDieYVr0BeFymRJW7cDFK5ge8ay0p55Cc/DLjk7yQPQS+CTCSFI3DEzm rhHntFPWo8s8mBoxlYvBTio3TYfad3n792GKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715126965; x=1715731765; 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=y1syOJovW5eId25dp/lIC5NMYcXKMWcKV21Z0vOpfbA=; b=twBcE7OYv4PnUW9YIAxisp7tcpFTCDLHD/CVhFYsz586OdNOGWq0COY83403r4mveP KFuNXuHOH1nJrVCauo4chRDwiQYHHCStSGBPdEyyvqQ8OEMJ2zYJuHcI3tyGpctxOqAT wJ0cPklRiYNK4v2cDD7ImR5n5AI1YvTAs3F9c0+b/MdGoLO6n8eVx8/0ZSEVInoZ0nju jMryWciuGmZkqaUT3WoXmnWTwYc/j/MuD4Q4hs/78/dgmiPLHp5HzldWSMdc+lKHg7Fs EnEygMPi5sWjQL8DgdH+aRvd+GjhP5krHpbFAqQyM2oEolAOHEIT0B22L6Tp992dzIR3 oAUQ== X-Forwarded-Encrypted: i=1; AJvYcCW1w3zte1dN3PC8xnJLNCTD9gzs3o708dUmRTdaUBIBkJqXsYPZZWzH+6LAGpRBdqEXL/6vdlB2xiwtUp/8EeFM29PvY6AEjV5TJsrt X-Gm-Message-State: AOJu0Yz0onBhH21yNhd3PPO5nV/+7pGU6VpbFbyJdOdvu2c+o2ESXDiG Cu85pZbN2UDInHIUbpsx2HLKum6ap0qAtXOmfuZekxW9kdUVQS6MCvV+kcTjXw== X-Received: by 2002:a17:90b:4ac8:b0:2a8:1fdf:b1b0 with SMTP id 98e67ed59e1d1-2b6166bfe0bmr1137740a91.29.1715126965497; Tue, 07 May 2024 17:09:25 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id d12-20020a170902654c00b001ed9b384b6fsm6802901pln.23.2024.05.07.17.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 17:09:25 -0700 (PDT) Date: Tue, 7 May 2024 17:09:24 -0700 From: Kees Cook To: Justin Stitt Cc: Phillip Potter , Nathan Chancellor , Bill Wendling , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] cdrom: rearrange last_media_change check to avoid unintentional overflow Message-ID: <202405071709.817AB45C0D@keescook> References: <20240507-b4-sio-ata1-v1-1-810ffac6080a@google.com> 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: <20240507-b4-sio-ata1-v1-1-810ffac6080a@google.com> On Tue, May 07, 2024 at 04:54:04AM +0000, Justin Stitt wrote: > When running syzkaller with the newly reintroduced signed integer wrap > sanitizer we encounter this splat: > > [ 366.015950] UBSAN: signed-integer-overflow in ../drivers/cdrom/cdrom.c:2361:33 > [ 366.021089] -9223372036854775808 - 346321 cannot be represented in type '__s64' (aka 'long long') > [ 366.025894] program syz-executor.4 is using a deprecated SCSI ioctl, please convert it to SG_IO > [ 366.027502] CPU: 5 PID: 28472 Comm: syz-executor.7 Not tainted 6.8.0-rc2-00035-gb3ef86b5a957 #1 > [ 366.027512] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 > [ 366.027518] Call Trace: > [ 366.027523] > [ 366.027533] dump_stack_lvl+0x93/0xd0 > [ 366.027899] handle_overflow+0x171/0x1b0 > [ 366.038787] ata1.00: invalid multi_count 32 ignored > [ 366.043924] cdrom_ioctl+0x2c3f/0x2d10 > [ 366.063932] ? __pm_runtime_resume+0xe6/0x130 > [ 366.071923] sr_block_ioctl+0x15d/0x1d0 > [ 366.074624] ? __pfx_sr_block_ioctl+0x10/0x10 > [ 366.077642] blkdev_ioctl+0x419/0x500 > [ 366.080231] ? __pfx_blkdev_ioctl+0x10/0x10 > ... > > Historically, the signed integer overflow sanitizer did not work in the > kernel due to its interaction with `-fwrapv` but this has since been > changed [1] in the newest version of Clang. It was re-enabled in the > kernel with Commit 557f8c582a9ba8ab ("ubsan: Reintroduce signed overflow > sanitizer"). > > Let's rearrange the check to not perform any arithmetic, thus not > tripping the sanitizer. > > Link: https://github.com/llvm/llvm-project/pull/82432 [1] > Closes: https://github.com/KSPP/linux/issues/354 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Much more idiomatic. :) Reviewed-by: Kees Cook -- Kees Cook