Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1122573ybe; Wed, 11 Sep 2019 09:42:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgXJ74GGYJ6AGADovzDqB1RwJbA3mkkCL32jKZDvbEvwFxkE9AYfQVwu8lqjySSO+gZEXo X-Received: by 2002:aa7:c0da:: with SMTP id j26mr37706026edp.40.1568220163257; Wed, 11 Sep 2019 09:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568220163; cv=none; d=google.com; s=arc-20160816; b=hpMVOz3K25PnaWyT/AGcJSM4lo8/udyDX8oJn9+jEqKkjrj1t6LyxV/gsYEW4+NK7D uMHvUESqIvwz7iEtODB1ujIR+x3kfrHG3l9wJV7WUm8LNUkjHA9L0phMh7fmWvraR2N9 hxCjEsCADTxQ1jIU92g32PHGfuvYM6Gy4HM1s0uymY+zU+AL0AAC1iY7jUj6mNGw+ZK4 LKLvHeAKMUrwCClr9s0iHWFwd0sv0eCI/fs+JG+KdwSMygzrFvGlgmnhnkeewVI0+gYs SqK274EVWzOpZZms92F2t6on3uwHRIIBdq2ApvGuOB5Mt5Tcx+pHa2e680pryclFe5iJ nSkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Tl8NmQTauJTkodtSWs25AtKBiKIs4gXgEL1Drv1zzhk=; b=cx17qKfc4V6I8CEKYDVQREcb6NzJeCHD7iiCe97pzXUiFYhlOG7kvp57zWif+JMY1U mt4KItlqCRHbIVvCKqSFrKE3ubJKC6M2psIG3n9TgMiFGRc4SPa4LnS1OCxFepe3Bqyw 9+AJFCRm0aI3NYs+5I8XvndmCBn9xIfapXEpQM5iBpach5sM74BIUh9muahAUZ8/SXf8 d9PN0+FQ2GOLl1DTm43KhnREGwWYxFMr+EMUARHit3mIO2iHs5Lg+0OCLfYeuh0cWNoB 6jVoAw1PGo07meSiKLbBgtWzGTl0HVLprQ4VnpYfRiU2+A8lqq1qS8qF3OreeTVICRF7 uRvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KrwK0M0d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si11353657edh.173.2019.09.11.09.42.19; Wed, 11 Sep 2019 09:42:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KrwK0M0d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729172AbfIKQkb (ORCPT + 99 others); Wed, 11 Sep 2019 12:40:31 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:33946 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbfIKQkb (ORCPT ); Wed, 11 Sep 2019 12:40:31 -0400 Received: by mail-io1-f67.google.com with SMTP id k13so32138090ioj.1; Wed, 11 Sep 2019 09:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tl8NmQTauJTkodtSWs25AtKBiKIs4gXgEL1Drv1zzhk=; b=KrwK0M0dhLOpf2xNKKt7rOC/ir8cAmxu7g3OknTESI8+ndgvUAupbL8zdtSpJ9q9ya scfVgs+5s3OgeLS4tDRLlTlyQvcHFeY6n226EBv3elBq6Z2BMNbG9esOCL/nhHIFYSUy uAeu2TM04i6KT5YtI9oix9nRO5cAFmXAGNXyouGLmXgR7nugb0KC0YkTaScMZZUMEQh6 EkZmBF3qzqz94I7bEwNr/SJgiFi8+0r0DmiZUp8chd3e4lzdbBfu42MptgfZ4l/zQkUe cHXsvM2IiBxyCBjIfFeb9BB2TUvi8z7qx3cT+osuZMmamwGPic6/fAVMt//zaD44jL5k vbew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Tl8NmQTauJTkodtSWs25AtKBiKIs4gXgEL1Drv1zzhk=; b=qxzf2hRA5XbMJ1F1vgWzxQKCIR6A8Nfi+D3E+p6kOWvlr3e+Cu3x/xhPxZMOYaR8/3 pPqAOL8Hzg8iXnGZ5l6kKzD6tDWCv7r983DJ5f2gwNOht0FNnqMH6I6pxxxqqqEUQX48 0xCY6jo65QAqY/WxppEUceT6qsTheZlR1g4o61YXSclFTnlUpiUln98EboApGX7j8XjK 8Ya6DoVz9bkn702V/6X8GNEf8IJN837VmNpoISyY/Mf1Z/qzbgHi/VFRqqXWNQFQiV/h b6Zg4VK+LJR4w/ke8AjyGKwJgXSrWT2q109huA4GEzq/b6Z3jhj+bukxVHRlkLEq4BJY MIRA== X-Gm-Message-State: APjAAAX+KnjvfmaVPAeTG9gALvS9YErIfwstvWR+oWSOoAMHuTIy2H+u 8hbkT32B6f6EsFHEW47wavmHpNkvDPU= X-Received: by 2002:a5d:9153:: with SMTP id y19mr703021ioq.109.1568220030163; Wed, 11 Sep 2019 09:40:30 -0700 (PDT) Received: from cs-dulles.cs.umn.edu (cs-dulles.cs.umn.edu. [128.101.35.54]) by smtp.googlemail.com with ESMTPSA id c4sm16912886ioa.76.2019.09.11.09.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2019 09:40:29 -0700 (PDT) From: Navid Emamdoost To: mkubecek@suse.cz Cc: emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu, Navid Emamdoost , Josef Bacik , Jens Axboe , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] nbd_genl_status: null check for nla_nest_start Date: Wed, 11 Sep 2019 11:40:12 -0500 Message-Id: <20190911164013.27364-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190910113521.GA9895@unicorn.suse.cz> References: <20190910113521.GA9895@unicorn.suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org nla_nest_start may fail and return NULL. The check is inserted, and errno is selected based on other call sites within the same source code. Update: removed extra new line. v3 Update: added release reply, thanks to Michal Kubecek for pointing out. Signed-off-by: Navid Emamdoost --- drivers/block/nbd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index e21d2ded732b..8a9712181c2a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2149,6 +2149,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) } dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST); + if (!dev_list) { + nlmsg_free(reply); + ret = -EMSGSIZE; + goto out; + } + if (index == -1) { ret = idr_for_each(&nbd_index_idr, &status_cb, reply); if (ret) { -- 2.17.1