Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp691043rwe; Fri, 14 Apr 2023 08:29:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZsoeoAjh7hPxorl3cxx9bSI1qhOMgewq1gGRWs2JuALSfPbuAV1EmvTjwUH/A5FmogR98g X-Received: by 2002:a05:6a20:a028:b0:d9:7a97:a7b9 with SMTP id p40-20020a056a20a02800b000d97a97a7b9mr10583896pzj.6.1681486165996; Fri, 14 Apr 2023 08:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681486165; cv=none; d=google.com; s=arc-20160816; b=jNQAntJ/Gxgtg9zxCgO7NtrJIAkXsiEOi+Q/jszlDK6ezFQCFFmahtE2bi9uuiRSq2 UdRRDVW2rXuKVYxc5EiVi5KFV/DiL4UM9mpzAgxgF3yTwknzdMetIHhznqXvVRU7K9Rk xWB/lCD02v7c43IhXbviJnCTClT4R4WsI+MkmYjrvRBjNi9iOGA8yfd0XtbSjyFQZVkq UEz7hI67UpehFFSkBthhZ90AYvBosiKpvW4E53G+AE3adfW6HKkWFkLFtIq6Gyalp+0u 9jnkrj8gGoXwD4OsIqGrIZpIrd4YtoiWWLCppW9OCgUuKLS0bs3aH1/+T08c9F+mzGke fc/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i+GOAo28JNAOCrRbLOeXmFJaGrbed0qacVaGMx/eMlQ=; b=RrThZj4xCfijR5Qkll7EhruoPuEOkSx14xVuf6yN0bkIuHFybCCWmxChqwbbt9Y5Xm kAWCaK5Ypj3WvEIzig2k1ZPGE9JIIzdYEPb2eD66PJWgqb9YEWu+AqP9pMRjElsfRx09 psBKqXMyq+gz7slcmLVl7AT1CXLT1o86iINJRd5ETrOmZjj9AFh2tuL6vnWlgdZdyrU1 epnDi9wM+kwaMaNY5XK4r5Pj7kw+BIWx542xeyHV15MeEOwCdbKTZkTNUetn8NL8e1mW 6t60dJaF6EEXvStl38aFc1mmBxqwdmAKbOH/4uaMvkZNms3N/6psC7R2J6mzYWuVpDG0 vWmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w185-20020a6382c2000000b00507806546e7si5235583pgd.501.2023.04.14.08.29.12; Fri, 14 Apr 2023 08:29:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbjDNP04 (ORCPT + 99 others); Fri, 14 Apr 2023 11:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbjDNP0m (ORCPT ); Fri, 14 Apr 2023 11:26:42 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68D7BCC26; Fri, 14 Apr 2023 08:26:10 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F7DD1756; Fri, 14 Apr 2023 08:26:05 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E1DE73F6C4; Fri, 14 Apr 2023 08:25:18 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Andrew Morton , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 4/5] memfd: Pass argument of memfd_fcntl as int Date: Fri, 14 Apr 2023 16:24:58 +0100 Message-Id: <20230414152459.816046-5-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The interface for fcntl expects the argument passed for the command F_ADD_SEALS to be of type int. The current code wrongly treats it as a long. In order to avoid access to undefined bits, we should explicitly cast the argument to int. This commit changes the signature of all the related and helper functions so that they treat the argument as int instead of long. Cc: Andrew Morton Cc: Alexander Viro Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-morello@op-lists.linaro.org Signed-off-by: Luca Vizzarro --- include/linux/memfd.h | 4 ++-- mm/memfd.c | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/linux/memfd.h b/include/linux/memfd.h index 4f1600413f91..e7abf6fa4c52 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -5,9 +5,9 @@ #include #ifdef CONFIG_MEMFD_CREATE -extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg); +extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg); #else -static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned long a) +static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a) { return -EINVAL; } diff --git a/mm/memfd.c b/mm/memfd.c index a0a7a37e8177..69b90c31d38c 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -243,16 +243,12 @@ static int memfd_get_seals(struct file *file) return seals ? *seals : -EINVAL; } -long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) +long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg) { long error; switch (cmd) { case F_ADD_SEALS: - /* disallow upper 32bit */ - if (arg > UINT_MAX) - return -EINVAL; - error = memfd_add_seals(file, arg); break; case F_GET_SEALS: -- 2.34.1