Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2446662rdf; Mon, 6 Nov 2023 14:44:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1ZXvQgzUue15a/lVdTzFAhcBFt4Wcxpjgbcs0L21rsxGkuu8xWZAcYWlbHT4upspClctp X-Received: by 2002:a17:902:d490:b0:1cc:5c49:6af8 with SMTP id c16-20020a170902d49000b001cc5c496af8mr1379729plg.25.1699310680860; Mon, 06 Nov 2023 14:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699310680; cv=none; d=google.com; s=arc-20160816; b=QuopvV1r3/ioqPIFrMyQ5c0YpZwG302UsnnlKMlKl78TFd3F9lbgUg7wFuKcMb1XV6 gRl6N4nasMsDlhQTSSf1bHd7nqZKZyanX7xqMduVPKknlONTWEvI/Q5OAVyzmlozkm2h zTEBUs7GvnKqaeK033Z8UyJjtnngvI8J8NjHdI0+YhUssv/3pPXLskNPfR1mpJu0Bx+W kUxN7Ua54c8g43xNpVsMww/c1qtvL9K0/KUkN3mwCn3CeyGLN0lmy2TeV51wdhNQo0Xp niGcvcXoahebsIU8H8v0VfBeh8WISrFyqIlH+Z8L9ERZF5EwyLn09EFGsp8XJ+rWKKFd bbwA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=3veDMgMfom/Ebt8NzFsbnB5XbU+H8vB/5Wx02VWqWU4=; fh=9FDSCK+9Y2LYRPmSjPSxQVBYY/Ln7f8eT196XXy5LJc=; b=y8wV/sCn6IuAiXAqtbJ50orPqoomgvc2cbQT57UFwwDqvyOafsNK+DomboOOYyy6hm wg280RgIW1vLMYahl/aQ9VDFRKxenizXUsRklezQiB2JSpqLRzurxKUIMbmeTAF3Ppf/ /X1zXBEghq6xqP0iH16RghsVTN3kbBKlfm8LwDj6oSX6kFH3z00UMSf/EyEsOVJrgIm6 hF1z057hlg2CFGPDlIrJ7BrdztPu9rd6ql4oSCsJ53saxZBsDwOTy2+7/0qo5w00TGsb XhLmLDti9RlBaval68/3CrW6gxk+y4ictKPF2P1I4rn52ZpqS14aRX7nATpWb1BhMagZ n2Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gYh1Z5le; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p22-20020a170902b09600b001c9c8c4cfb6si9247479plr.214.2023.11.06.14.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:44:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gYh1Z5le; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BF25680E6598; Mon, 6 Nov 2023 14:44:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233399AbjKFWoe (ORCPT + 99 others); Mon, 6 Nov 2023 17:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbjKFWoY (ORCPT ); Mon, 6 Nov 2023 17:44:24 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D9E1D51; Mon, 6 Nov 2023 14:44:22 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6bf03b98b9bso4608268b3a.1; Mon, 06 Nov 2023 14:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699310661; x=1699915461; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3veDMgMfom/Ebt8NzFsbnB5XbU+H8vB/5Wx02VWqWU4=; b=gYh1Z5leu1kHh83t/Wb7+ZHV3GYzJpbWoGTywKpmJwLVjV+1m26aYz9PlXDihL+hwF e2O1gGkK8I4oRh0ZTnWm/wSV1B2+h5Il9c84LETPYN+MNmhxtVn3gonIMnk2EuKZgUZ7 o32nm0w1u83QMoe/3g+AEb+nxxErjFiHDm+BCFjpO5fhZGrLeVpsqIbGyGEO0OsXlHMi FyTzYoWyHk1YmqrYhGwlGGlMTYcyELqoIJC5QC/k/lHRrAxK4KVY4mBal3JCIE01+tJd YY4D0jDTY+3CE5WzK42mXncXa9CmZfy1iERd99/PpyITEdF8VYu4ntgOZ8JwVQykXxA/ KAHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699310661; x=1699915461; 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=3veDMgMfom/Ebt8NzFsbnB5XbU+H8vB/5Wx02VWqWU4=; b=aezak5SWOK8YM3tSB0/fhTYE0zvBtYBgIG64pczKhV1NWYClVU4uVmt9ZE6iqcpC74 r4URD4RwuNjRXFGCm8OKJ1pc3/vWqmGxcebpFnJAkd0kgTNJvb3cuevsbRqzo0uq0WLA sWQ3eayecJsZMseKq+pdrsB2pWtF1EwNi2LEutfNcybxbnCclQcXaFDrZPQ6EEH5MuRm UST6HIubpS+r9tDTiRKXzN+e0/28cfz9pMc4w2kMW/NmFQrW6HfY8ts8+jdUvSm2vcYZ nAD0qRxpn2kr2eeyilzxTOZEJAm3bCHpXXtA0WtqFSsaq5/5b07xj6eFXhTKkCbJ9wiy 3WRg== X-Gm-Message-State: AOJu0YyHLeudC9m1l8pZ0r1EMlprGn/dW7XYfEWlmOlQHXlnX8yYdbha FEX1OzwRdysmub6aHE+ieZ2zl5uX160= X-Received: by 2002:a05:6a20:a11c:b0:17b:62ae:a8bf with SMTP id q28-20020a056a20a11c00b0017b62aea8bfmr1008086pzk.30.1699310661370; Mon, 06 Nov 2023 14:44:21 -0800 (PST) Received: from carrot.. (i223-218-131-225.s42.a014.ap.plala.or.jp. [223.218.131.225]) by smtp.gmail.com with ESMTPSA id du8-20020a056a002b4800b0069346777241sm6216292pfb.97.2023.11.06.14.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:44:20 -0800 (PST) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, Philipp Stanner , linux-kernel@vger.kernel.org Subject: [PATCH] fs/nilfs2: use standard array-copy-function Date: Tue, 7 Nov 2023 07:44:16 +0900 Message-Id: <20231106224416.3055-1-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 14:44:40 -0800 (PST) From: Philipp Stanner ioctl.c utilizes memdup_user() to copy a userspace array. An overflow check is performed manually before the function's invocation. The new function memdup_array_user() standardizes copying userspace arrays, thus, improving readability by making it more clear that an array is being copied. Additionally, it also performs an overflow check. Remove the (now redundant) manual overflow-check and replace memdup_user() with memdup_array_user(). In addition, improve the grammar of the comment above memdup_array_user(). Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner Link: https://lkml.kernel.org/r/20231103184831.99406-2-pstanner@redhat.com Signed-off-by: Ryusuke Konishi --- Andrew, please queue this cleanup patch for the next merge window. It's a little early as the current merge window isn't over yet, but I haven't had any problems with it and I feel it's better to focus on other series, so I'll send this now. Thanks, Ryusuke Konishi fs/nilfs2/ioctl.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index 40ffade49f38..cfb6aca5ec38 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c @@ -872,16 +872,14 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, nsegs = argv[4].v_nmembs; if (argv[4].v_size != argsz[4]) goto out; - if (nsegs > UINT_MAX / sizeof(__u64)) - goto out; /* * argv[4] points to segment numbers this ioctl cleans. We - * use kmalloc() for its buffer because memory used for the - * segment numbers is enough small. + * use kmalloc() for its buffer because the memory used for the + * segment numbers is small enough. */ - kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base, - nsegs * sizeof(__u64)); + kbufs[4] = memdup_array_user((void __user *)(unsigned long)argv[4].v_base, + nsegs, sizeof(__u64)); if (IS_ERR(kbufs[4])) { ret = PTR_ERR(kbufs[4]); goto out; -- 2.34.1