Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp198886rdh; Wed, 7 Feb 2024 01:59:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxhG7+UXLiGNT31uW7B3C/eImNl8ZiYpmmvmDM7o4s5xBdIe0j82A9nmH0rMa8KTYwGh9y X-Received: by 2002:ae9:e715:0:b0:785:8e15:ccdc with SMTP id m21-20020ae9e715000000b007858e15ccdcmr4584796qka.74.1707299947196; Wed, 07 Feb 2024 01:59:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299947; cv=pass; d=google.com; s=arc-20160816; b=l4xykwvnLSbTqBFPGGBHNKPEYAH3SPfpKMAztFDGv1aJeaGWbahd9BKWCgYF3pS5Ts sEd4/7YIHskeEVbQiJTyERkWBpsmNLjZnleq22D6eNb+r3DIP2OsjviKJtH3yh5toitv 5a/ZcORLG7fD7IVfTFHdw1PJBb/6zhM++1VWS9B8hn7MA6lEgoI4QuSy+31IBTYvS6PP dB8HuRNn6QLPCZYJSB+vj7TF/n+UePYDC80SBQ9Oj8vCBoIJa8IeJ/OuUENY4k/nC4y7 M6IohCpIDk8NLJx46k0+65TTNiqbN6JRvnKK1OrmGP1q38z0Mp1m10wwvK5mDsGl/4wt kzsQ== 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=RuHPKI2TyLy54/VY5cZT1BURMT8lyVeU8gfTIG1u+9A=; fh=YLRqtjyoZ1AnXMoeWZZNpiUoUiuzPmNdubJNhjBvqMQ=; b=Td2BV3JPtrxv26pGPiVFZEHRHYXdPoVoOE40c71TdkwO9BmO0ZcpooEHrJ30J+mCCr L/crRpSXxq/Gl75DKJ39XHwlplaK9NSWjnDdZRyj4VNJXNBMG/RuCUCmEMsNPdlnS4KE 9tA98P7b+0GHG/8Vl4toiafughlrmeeHLvGGH6eRt0MUDrEQVZ83f2i3hjM5GZlVL84n TWGvWdnlHcpYz71DyMK703967TewhsV6nW/RGEPA1Bw9hDtn+v35PmCdzFJLtcTIl0lS n3hCR/DePiKO5REvLcykPF8Orpy1ZAcLjAC+0QppuSKiBKBq+XjG8aOALdJHmGb3JFHk XydQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S2MgBBB/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-56271-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXhVCCOktvDW3yvPHNYN355dlmGebC8jblajdNQN1iELkq1Nj+7FmQqegLSgvxzodaQWPdbBUpfI59AG2aYOhJaeYlz5vx/q4BHiI7p/w== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x12-20020a05620a098c00b0078586cf4e94si753872qkx.362.2024.02.07.01.59.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:59:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56271-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=@kernel.org header.s=k20201202 header.b="S2MgBBB/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-56271-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 E08571C231CE for ; Wed, 7 Feb 2024 09:59:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A817B24B2C; Wed, 7 Feb 2024 09:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S2MgBBB/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C15EC23775; Wed, 7 Feb 2024 09:58:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707299927; cv=none; b=k7g+WedqBivL3DfQ7nbCdNHVvDerIbeRzHgxoK6SQtdW1JV1cv+fHsjyrMPjVa/Y9tuiUuGFaNH//HbiJLW0Bul8sZOVnKmHO6d40U0ug0DojOd0LUq3fzJe/uLYQq/iIEC0UuR3NxRYs45LHhqj9ThdtgOBvZlzOv5sWdpOcDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707299927; c=relaxed/simple; bh=mhF0TN1HXB7tfV4/QPwCrW1HhS6tDIF7W7UL/ee/wug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jz6B/l/XSnnc9AfBak0OX9PZsQHk9xuPN0seUzn/FJpi1qr5/q+shvkxyVeC0CFQDTN8qthrtTpmsIHYYCMPVpC6fo2O3A/WPDSE/xik7eCLqcD9/huAUiH48Z/9WuwGaolHFr3QJYzVNzcaAni1BP4nXUi/qA+qaUukNVYYWoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S2MgBBB/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0698C433C7; Wed, 7 Feb 2024 09:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707299927; bh=mhF0TN1HXB7tfV4/QPwCrW1HhS6tDIF7W7UL/ee/wug=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S2MgBBB/KWNsEKOdmS2YH4MvwV3afe7+6p2jNoBbTWMoqI0vaEfA2GNnU8x2DIJha POBBVd60eLs3Or3hF4t2E/aIUZ0fFyPeyROf85vtWwXjNeGFuaMOWRlXXYSsEMzwic q/hKR7NQp5GkSAwcurtsghAP/CxmaEKGcFnCJl05NeiJAspg/bzPCXnxlaswI/OiVd lsQQOySrPsI48odWNkZppXnXQ2GD9Xp7A/GJ47r1j/LfPflx69XHAyhw3lepx16gfP sO5vb+XY/DTXf46D8bhZlZS2UyEHmNBudWGRVqTNxOoBBTf3dJaZPWaBuB+6XRnsVP rIUaU++Qpv4Ag== Date: Wed, 7 Feb 2024 10:58:42 +0100 From: Christian Brauner To: wenyang.linux@foxmail.com Cc: Jens Axboe , Alexander Viro , Jan Kara , David Woodhouse , Matthew Wilcox , Eric Biggers , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] eventfd: strictly check the count parameter of eventfd_write to avoid inputting illegal strings Message-ID: <20240207-hinkriegen-trugen-8f219d8840a8@brauner> References: 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=utf-8 Content-Disposition: inline In-Reply-To: On Wed, Feb 07, 2024 at 12:35:18AM +0800, wenyang.linux@foxmail.com wrote: > From: Wen Yang > > Since eventfd's document has clearly stated: A write(2) call adds > the 8-byte integer value supplied in its buffer to the counter. > > However, in the current implementation, the following code snippet > did not cause an error: > > char str[16] = "hello world"; > uint64_t value; > ssize_t size; > int fd; > > fd = eventfd(0, 0); > size = write(fd, &str, strlen(str)); > printf("eventfd: test writing a string, size=%ld\n", size); > size = read(fd, &value, sizeof(value)); > printf("eventfd: test reading as uint64, size=%ld, valus=0x%lX\n", > size, value); > > close(fd); > > And its output is: > eventfd: test writing a string, size=8 > eventfd: test reading as uint64, size=8, valus=0x6F77206F6C6C6568 > > By checking whether count is equal to sizeof(ucnt), such errors > could be detected. It also follows the requirements of the manual. > > Signed-off-by: Wen Yang > Cc: Alexander Viro > Cc: Jens Axboe > Cc: Christian Brauner > Cc: Jan Kara > Cc: David Woodhouse > Cc: Matthew Wilcox > Cc: Eric Biggers > Cc: > Cc: > --- Seems sensible but has the potential to break users that rely on this but then again glibc already enforces a 64bit value via eventfd_write() and eventfd_read().