Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5046927pxb; Mon, 15 Feb 2021 08:10:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwq00z9gahdapSDWMASLEMkIIvsr9I5YJJkrPAm0gKhyo1HPQEHOwtalBoYuofB/roG+i0s X-Received: by 2002:a50:f782:: with SMTP id h2mr4774009edn.245.1613405401069; Mon, 15 Feb 2021 08:10:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613405401; cv=none; d=google.com; s=arc-20160816; b=Ch3QlLvpEFcl1tcJddXF0vj0rHgkP0C6wFkgorFNAOyGQHV6SLcnOjb34lDqcrHXWI o8X9PX+i7Sg6L0jV/Dz67fJWD8Mc82sKwZRJCLAt8ohq7xyzUbAMplF2QoUA4bKEo7H5 JIIe+WR+k9Z4SFiESifgI4NabvxJz5dMqGgKkG2E9pZmUEeTW1lDjcIYExuC/hOPqJLb Srx37dYhI6unSCF7gtEcizh2LG//dgF0iy1WhR/wod3GD2amWKr/gQ3/PuPJJf+W6Zcd +ckZYGftzww99ySw1jqXAsLLVgnek2iNTPbPWh1M/ksRLj3iu8ivnZaG/d01Ul/RiGAt 3Otw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G1wdJcI/ttKpfHTPbtZ6hLT0ptYA2kn1R9m65hZmuPk=; b=Kxg9q8Vf+qfguhDSHl8ihS8zheJ6W966sG5yMSa8wpeuVObcKJy446GvkWnzXem4KN 806hl3Q9bEr8e4Ra8OG/lv4y0uqInwhaW9KRrmXcDUiKTo5DzEMPJE49BhEtE4mAYHUU jYQLJVsRTFvS0kSfb5un/Li1q/c2LumHHxa3L3WnbAT2WGspcWns5Ivdj/Zskc9u/SQW 2fznbivEXFoED/rTT26nnZeQKYgplb/a2GhtgHDk7276I33EXHe3XsoqmEh+KL+sOuGl QBtc1sk5RWiGwvClB8z7yzPCEw3OUCjjSm/0WEYILVzJJcTG/S+3QECGRb2wRphQj6Eg 4c7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=enI9cw1X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si12262533eja.255.2021.02.15.08.09.37; Mon, 15 Feb 2021 08:10:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=enI9cw1X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbhBOQI2 (ORCPT + 99 others); Mon, 15 Feb 2021 11:08:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:45590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231376AbhBOPdH (ORCPT ); Mon, 15 Feb 2021 10:33:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 891C864E64; Mon, 15 Feb 2021 15:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403046; bh=r2yip97vPP4YlZD2qpuCsmsTqFzhko98rZRcExv9fjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=enI9cw1Xz+FMvO2mQWkTALmoipHLemgWgsFq5M8FgUr95U/TzBOgtC0JiEfz2DzV7 1InSzc0gkOVE1kPQvysgS6fO+okBGuXqlIyp/XO+Bc0tBQ4RyvyIdh/q0+fIN9qV/G j6+uak/GBRvNvfXsL3A6FqNeU7cnb9FL4dEeR5KQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+1bd2b07f93745fa38425@syzkaller.appspotmail.com, Sabyrzhan Tasbolatov , Santosh Shilimkar , Jakub Kicinski Subject: [PATCH 5.4 58/60] net/rds: restrict iovecs length for RDS_CMSG_RDMA_ARGS Date: Mon, 15 Feb 2021 16:27:46 +0100 Message-Id: <20210215152717.240042606@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sabyrzhan Tasbolatov commit a11148e6fcce2ae53f47f0a442d098d860b4f7db upstream. syzbot found WARNING in rds_rdma_extra_size [1] when RDS_CMSG_RDMA_ARGS control message is passed with user-controlled 0x40001 bytes of args->nr_local, causing order >= MAX_ORDER condition. The exact value 0x40001 can be checked with UIO_MAXIOV which is 0x400. So for kcalloc() 0x400 iovecs with sizeof(struct rds_iovec) = 0x10 is the closest limit, with 0x10 leftover. Same condition is currently done in rds_cmsg_rdma_args(). [1] WARNING: mm/page_alloc.c:5011 [..] Call Trace: alloc_pages_current+0x18c/0x2a0 mm/mempolicy.c:2267 alloc_pages include/linux/gfp.h:547 [inline] kmalloc_order+0x2e/0xb0 mm/slab_common.c:837 kmalloc_order_trace+0x14/0x120 mm/slab_common.c:853 kmalloc_array include/linux/slab.h:592 [inline] kcalloc include/linux/slab.h:621 [inline] rds_rdma_extra_size+0xb2/0x3b0 net/rds/rdma.c:568 rds_rm_size net/rds/send.c:928 [inline] Reported-by: syzbot+1bd2b07f93745fa38425@syzkaller.appspotmail.com Signed-off-by: Sabyrzhan Tasbolatov Acked-by: Santosh Shilimkar Link: https://lore.kernel.org/r/20210201203233.1324704-1-snovitoll@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/rds/rdma.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -532,6 +532,9 @@ int rds_rdma_extra_size(struct rds_rdma_ if (args->nr_local == 0) return -EINVAL; + if (args->nr_local > UIO_MAXIOV) + return -EMSGSIZE; + iov->iov = kcalloc(args->nr_local, sizeof(struct rds_iovec), GFP_KERNEL);