Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp641366rdb; Tue, 23 Jan 2024 10:04:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFml/w/A8/wx/x7fDk9voUqeSbBE7G8dfPaa96Qm8pMtgFklV/lOxIwa1Rf4A/9T/DrKr1M X-Received: by 2002:a05:6808:1521:b0:3bd:4b9f:7f58 with SMTP id u33-20020a056808152100b003bd4b9f7f58mr287059oiw.91.1706033041532; Tue, 23 Jan 2024 10:04:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706033041; cv=pass; d=google.com; s=arc-20160816; b=CGc8mBJdii/hxE9B0a09TmwkmBTnyLMI2bzBp+kcoYH9n977ITrxjOoO97p9jQwwll wlOzF8AqgZhyEyHBp9+eujpVl8x4Iu0ejQnBcDiIAdAc7UK/HV+yABQ2BswvF3pAnoPs oWracttYJ8gZLo762swHHXb5qaEBTyYF53zEqnBuPPMne91FaWX53S52dQ2pUE6EfauS eOGAPa8q0TPUJSwjVafcZRsNlyZiSnBO54mPxtqrQowJYTFassrqEIixzzpdgW5MsEs6 JjSo14QyQQxFmL5atk5X5/jDnVX5y9TifrLRapvkhgc0dAcV/nKC74EBzkYhxj3q4OAs +aDA== 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:dkim-signature:dkim-signature :dkim-signature; bh=/QT8OmiiMqa92U7O1bt84T4KaCJPt04c3cPvTWRcJwE=; fh=Xvu7kzrg0+AamKbzN3BQPEDdmMcf7zaozKMkatT+DAA=; b=nxAp1u2/qkiiVZfHknuf73cAZXxI9cbfhFCXscQ+E3ZdZ8x8ArfXJBa5oWHHn+PwBe MaUpnWgttubEBdGVF1KClu1OkN9AfQZMw+ArVJj2Gj0kYsRDjQBQxOZo1B215iozMDIb qBF/6Jk5pg8O6czmrjxwoQ5BeOz5id9FIDibgDMFNLdEtO8M4MWpCIFH9oLT9BW39Jji McuCTjVU1K69qEONErj/QW3sX3Qnvqz0J7VS2/X2nh7n4NMe3VJF5cY7ip9Qpi7FCMLh FGPR9EEIJ+LWS9qgVU9ETWarJFvdPDSDuGk6ZRI8fxT0s5+LBooFDpn15PdlKVeldJyz 8QKw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="0n/i9ENU"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="0n/i9ENU"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-35841-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35841-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k6-20020ab07006000000b007cec9571054si937181ual.36.2024.01.23.10.04.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 10:04:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35841-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="0n/i9ENU"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="0n/i9ENU"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-35841-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35841-linux.lists.archive=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 338BD1C23761 for ; Tue, 23 Jan 2024 18:04:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7B7881AA8; Tue, 23 Jan 2024 18:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="0n/i9ENU"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="BCe2B2BX"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="0n/i9ENU"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="BCe2B2BX" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 555D4823A5; Tue, 23 Jan 2024 18:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706033013; cv=none; b=ECE/4HgR6yY2EP9agebjBh3ew2DqgAGfbX9lZvLFquQ79OhwUCxk0MCBwtP0OtTHISU0khL1kWHQ5rQlBdHJ1z+y/kW4oroH+g6LOm6hL/Inp8w7kiOTQ9he7cBUhDmpZQ6xA0U1rwQA5pwTRQ8HHvA26ZreYg1LRKAyaHe5sIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706033013; c=relaxed/simple; bh=FM39C5+dDJIqtcQ0V6pUv3Btv4UXQxsNjRrxNWs2RB4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GbIvcySQ6oweJJR/ec25SmETxERs6MCLyGrzqhyJd+9akVAWrRd8VoG3/IhkQAEthae/IpMTuXmPCS5pR3i5Ybk0H9GORq9LfqbzPKqvggFiG+CClAJ4//3ujkpMxnqNBJfK8ODmNPRCi94rUdNAk1iOlFV94s7KS5Hwi8b68Nk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=0n/i9ENU; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=BCe2B2BX; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=0n/i9ENU; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=BCe2B2BX; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7F7061F79B; Tue, 23 Jan 2024 18:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706033010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/QT8OmiiMqa92U7O1bt84T4KaCJPt04c3cPvTWRcJwE=; b=0n/i9ENUDsQh9LBixNC7gGqZ651FxSuCvFKxcGzk/HoaY0lPCLkXNANCvKI20s3HNHKb2A 9HiLTNEduWciHfSXvte0DrXgWl4r9mQj1VzXtaz/kOkc2RtxBLMaShbOABbdygoYSdvUZ1 1nlwml6oX50bZJYmS8zbunxCGBdtj9w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706033010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/QT8OmiiMqa92U7O1bt84T4KaCJPt04c3cPvTWRcJwE=; b=BCe2B2BXIUumxD8VmU7hjWDe0x75claIvmiDVzXbqZtyqJCJtM01gXESQpifAu5vMFDLjk A51p7ZHe4FHWqFDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706033010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/QT8OmiiMqa92U7O1bt84T4KaCJPt04c3cPvTWRcJwE=; b=0n/i9ENUDsQh9LBixNC7gGqZ651FxSuCvFKxcGzk/HoaY0lPCLkXNANCvKI20s3HNHKb2A 9HiLTNEduWciHfSXvte0DrXgWl4r9mQj1VzXtaz/kOkc2RtxBLMaShbOABbdygoYSdvUZ1 1nlwml6oX50bZJYmS8zbunxCGBdtj9w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706033010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/QT8OmiiMqa92U7O1bt84T4KaCJPt04c3cPvTWRcJwE=; b=BCe2B2BXIUumxD8VmU7hjWDe0x75claIvmiDVzXbqZtyqJCJtM01gXESQpifAu5vMFDLjk A51p7ZHe4FHWqFDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 70607136A4; Tue, 23 Jan 2024 18:03:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id O3xtG3L/r2XGKQAAD6G6ig (envelope-from ); Tue, 23 Jan 2024 18:03:30 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 17E13A0803; Tue, 23 Jan 2024 19:03:30 +0100 (CET) Date: Tue, 23 Jan 2024 19:03:30 +0100 From: Jan Kara To: Kees Cook Cc: linux-hardening@vger.kernel.org, Benjamin LaHaise , Alexander Viro , Christian Brauner , Jan Kara , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 37/82] aio: Refactor intentional wrap-around test Message-ID: <20240123180330.2br6kzg2m3lbyrva@quack3> References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-37-keescook@chromium.org> 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: <20240123002814.1396804-37-keescook@chromium.org> Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-2.60 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; RCPT_COUNT_TWELVE(0.00)[12]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,linux.org.uk:email,chromium.org:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -2.60 On Mon 22-01-24 16:27:12, Kees Cook wrote: > In an effort to separate intentional arithmetic wrap-around from > unexpected wrap-around, we need to refactor places that depend on this > kind of math. One of the most common code patterns of this is: > > VAR + value < VAR > > Notably, this is considered "undefined behavior" for signed and pointer > types, which the kernel works around by using the -fno-strict-overflow > option in the build[1] (which used to just be -fwrapv). Regardless, we > want to get the kernel source to the position where we can meaningfully > instrument arithmetic wrap-around conditions and catch them when they > are unexpected, regardless of whether they are signed[2], unsigned[3], > or pointer[4] types. > > Refactor open-coded wrap-around addition test to use add_would_overflow(). > This paves the way to enabling the wrap-around sanitizers in the future. > > Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] > Link: https://github.com/KSPP/linux/issues/26 [2] > Link: https://github.com/KSPP/linux/issues/27 [3] > Link: https://github.com/KSPP/linux/issues/344 [4] > Cc: Benjamin LaHaise > Cc: Alexander Viro > Cc: Christian Brauner > Cc: Jan Kara > Cc: linux-aio@kvack.org > Cc: linux-fsdevel@vger.kernel.org > Signed-off-by: Kees Cook Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/aio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/aio.c b/fs/aio.c > index bb2ff48991f3..edd19be3f4b1 100644 > --- a/fs/aio.c > +++ b/fs/aio.c > @@ -796,7 +796,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) > /* limit the number of system wide aios */ > spin_lock(&aio_nr_lock); > if (aio_nr + ctx->max_reqs > aio_max_nr || > - aio_nr + ctx->max_reqs < aio_nr) { > + add_would_overflow(aio_nr, ctx->max_reqs)) { > spin_unlock(&aio_nr_lock); > err = -EAGAIN; > goto err_ctx; > -- > 2.34.1 > -- Jan Kara SUSE Labs, CR