Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5075905pxb; Mon, 15 Feb 2021 08:53:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrCRk46uW3Z9lMSDpXA1DtEEu/eKcE+u68rRAYlSCiOwaJgdVO/pI0EUt2XBt06AuMdnqI X-Received: by 2002:a17:906:dbd0:: with SMTP id yc16mr16591087ejb.524.1613407997997; Mon, 15 Feb 2021 08:53:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613407997; cv=none; d=google.com; s=arc-20160816; b=CnV3UCXkpTJgZsiPnRI/vCnKDXCXfnaqaYmTB1xUbbneJTyIRtItFvZGCm7i2+ts7A givI7vF1V34fYiwnPLz/jMCmOt37NIOnT7y8H8GQQ5RwcJrx+AEWkXKpzBZB0nJXYd2O iVfv7gBkUFwXuI23m06rTqnQKxl6jmg5i58C5DQePs19HmuenDOnXs1IR9dP1WlcikMJ olekJBsJlH7iQ3X1GDuHQyRd/VVw4wMta5Ziu/Vmv7wL3EGEJlXMMrTp+aE5udf/gGvN y9S/kwkmQd2bUAzcjjUxktuNqyjjJnL2ES+s006LCugbOEZ1YeI96rbYRu434qQB1/48 RQmA== 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=9r8voN2NGQEtA/yR7q77keN/LAltlosVaEBL83/Oqa0=; b=vj7Uy8UHTFDykm5KSND6gHRcVIj9HBBiXC3RRMYJoH5uxGcAMlHj43S7yOR/ahk9FG XGEIdmU3w5QXahyyUTbwQaCIlvsSA2s6iB17gznapdzbl2/ieArLwuS+GEStZtS/KM0b K06kF9rSa6bNWjenwEww2oykgSvnI2W4lZQCWFJ3jVlctH8cMiHfxcxBNO7ILI1w8rFn 0/97D5tncCanhdh7bydX8Z/f8cKt4cpf3ZHlTgLoF52tR14MSHlMGmX3cnh5Wj19lIv3 OLYHiEaWX8ncJ71ENa2u3HHCDSYYtNtP3BNUp7RuZG8Ynqxf8jM8VVb1eA2swZzA0Jsr Ziyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aDlxdZo6; 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 i1si12470448ejb.687.2021.02.15.08.52.55; Mon, 15 Feb 2021 08:53:17 -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=aDlxdZo6; 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 S231621AbhBOQwW (ORCPT + 99 others); Mon, 15 Feb 2021 11:52:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:49602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbhBOPli (ORCPT ); Mon, 15 Feb 2021 10:41:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F09DD64E40; Mon, 15 Feb 2021 15:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403294; bh=hiQF/kE50FNymjssLrp3Cu0Zy1HYv4Dh1/FJ+d5gpPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDlxdZo6LeiY/IQY4gJkdW4667sapeX7QmmXEYlUYZGDTs+2UH9hmqa5TwY1/Ej4Z 00Ig3ogGjmaaAiMGApTzbw3OUg+bruq9GkGikG4dvrtV5Px+2dHBy4sem4MdDb69+L qQBznjw+N+JvzWVQi165ODQjniDhrP7SC6Ep7hpY= 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.10 101/104] net/rds: restrict iovecs length for RDS_CMSG_RDMA_ARGS Date: Mon, 15 Feb 2021 16:27:54 +0100 Message-Id: <20210215152722.729594843@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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 @@ -565,6 +565,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);