Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp578545rdb; Thu, 2 Nov 2023 11:39:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSklHY6cmdrt9oTsPBmBBmUG6xtK/xGkj7VTOz93FZGl8qsbx3dPv2H/qRgmm9DT0db9xI X-Received: by 2002:a17:90a:94ca:b0:280:1695:7b5 with SMTP id j10-20020a17090a94ca00b00280169507b5mr14777178pjw.12.1698950354642; Thu, 02 Nov 2023 11:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698950354; cv=none; d=google.com; s=arc-20160816; b=CY88YklfUZH/PrYRvoGWB+NRN4S2roWJ8+EkBsQHFMkPHhUUZw43Sx9nDOj2N23sIU amV7fYkBz4vtNdFowCQMkEvvcu7pyeKze9OWYVNvMfTPH1Ub7afeyCYLI3YtNAq+uVfh EvI0FunwWrc+Y5LjsXvQkg5+PQmINwpkAHSoYRCtyzoPhuJNAB+5mh1RJQFT409iX6Yt Clf627cZJ9hhrNGFJ/GPKIN83FImvei/0BpFiBOxNgQBCRwzupUwip1D6JuI4xd9XJYI eoO3I0pTXZeTVb0vs+17mcHHLAs4al0G+7/fp4u1r+l0TX5Q2hWRHc1/EFJHh6ZWbAwh UsSA== 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=4TMeJ+np4weC9A1EJ0nwAbg03A0sROonQrm4coY6tYI=; fh=t8VJt35CPT5KzOZjOzVKkyLcvi39Fs8qsCdUkkq2eZc=; b=EfMmZkTmu4vBnPdZEmA9ytrm+1ZSgO5h495+YisZdoiR0shFmy9URTy2sBgT8uhGJz uMo/EahBtHITYgd7QmuL3KYGzrXwtPU/1w9eQdDwwh9XSjlAIlqNr3dvzT+72A9ERSZl ISgdlmyc0DWzgEAPAk77iDCgzA5/oqFmGwLbMsMDffD7ds1gg95q+TrA3fcFiMLAxW0U a5Dwi2D2neAb8soCDEw7fhqmjzhVsYF2kNWlWmv5Hh1DQ1qF+SAiDdtMrdr6ihGeg0zi d3O3RSKPuMwx1a/ezcEXJkHGb8Ixu2kg2pgrechOMv/naHeqHqXs+D4LyLAI6NKahZrn hhIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VmzPs2uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p2-20020a17090ab90200b0028014e41ff7si145869pjr.48.2023.11.02.11.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:39:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VmzPs2uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 404DE822741D; Thu, 2 Nov 2023 11:39:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377235AbjKBSjH (ORCPT + 99 others); Thu, 2 Nov 2023 14:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377347AbjKBSjF (ORCPT ); Thu, 2 Nov 2023 14:39:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57DDFDB for ; Thu, 2 Nov 2023 11:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698950290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4TMeJ+np4weC9A1EJ0nwAbg03A0sROonQrm4coY6tYI=; b=VmzPs2uK+KUJg6NLniiQmJgcqFyNM0WgPZnuGJX9ecqYUKqF+lMLoX/kZMCGxrXwjF7zFD WG7Q2QXAycUpex8WuSNg5dISpRu+aSqtCZROfqKrY7tG6ScyPXCjlT2XPwrZsKQFvxmF34 j3fn6atoDYdUwBBaCcZLwYjGPIGpF5w= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-qLjsdeYKNlODMT0Ln3aBBg-1; Thu, 02 Nov 2023 14:38:09 -0400 X-MC-Unique: qLjsdeYKNlODMT0Ln3aBBg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4084f909b4cso2626065e9.0 for ; Thu, 02 Nov 2023 11:38:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698950287; x=1699555087; 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=4TMeJ+np4weC9A1EJ0nwAbg03A0sROonQrm4coY6tYI=; b=l1sa1/6Eyv9HZP6R0CU9Sg5SJX64NoaNMYBtefZu/LZzK5yZBbWgrSvTP4g3NUWIqs Sw23aq4ASdLNXwfgz3n9AHHct15S9opP+YCjIG9pNE4dgF6LKHp3YEQgkhNi1b7EEDfP kyRQ3tza10Wqa8e16HCNo7ydIMnKhuixlpZzNEkaCJu0XwUsCnpLvK7cwWkvli13vxz7 wfLrMZMOJiw1cDJQ5OYPZtAIHNrqyhKRulSnOdvyzAh6g07OmcY5VZhyzKROACQKnvN6 q//Qa2e/+hRj/0kcyfJQmf1uHDWTEgBLXN7thL22hsbKCHTGk9dBO0a6syfM144mDXp/ TFLA== X-Gm-Message-State: AOJu0Yxq95SupyGlD62JnLJBDVHOGs4PnmwsxpJIQdGvEAzEfZj8iDe9 anknDzfbqPwtemAvDmpH8RRKji5HOWQoY+shvDQkLZyTHxBvMjeYs0hwGAsKiaUY8zwSp5ctNJt 2RKIVwH9p5tbZHDyTK3SQz30+ X-Received: by 2002:a05:600c:35d6:b0:3fe:21a6:a18 with SMTP id r22-20020a05600c35d600b003fe21a60a18mr15734354wmq.3.1698950287728; Thu, 02 Nov 2023 11:38:07 -0700 (PDT) X-Received: by 2002:a05:600c:35d6:b0:3fe:21a6:a18 with SMTP id r22-20020a05600c35d600b003fe21a60a18mr15734346wmq.3.1698950287375; Thu, 02 Nov 2023 11:38:07 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id k15-20020a05600c0b4f00b004094e565e71sm306179wmr.23.2023.11.02.11.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:38:06 -0700 (PDT) From: Philipp Stanner To: Ryusuke Konishi Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, Philipp Stanner , Dave Airlie Subject: [PATCH] fs/nilfs2: copy userspace-array safely Date: Thu, 2 Nov 2023 19:37:51 +0100 Message-ID: <20231102183751.47413-1-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 11:39:12 -0700 (PDT) ioctl.c utilizes memdup_user() to copy a userspace array. This is done without an overflow-check. Use the new wrapper memdup_array_user() to copy the array more safely. Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner --- Linus recently merged this new wrapper for Kernel v6.7 --- fs/nilfs2/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index 40ffade49f38..6a9dceebb18d 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c @@ -877,11 +877,11 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, /* * 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.41.0