Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp52510rwl; Thu, 23 Mar 2023 12:33:13 -0700 (PDT) X-Google-Smtp-Source: AKy350YYsdUYZ0HNGcCCl/cww9ATL4Sg/YIED5eWFJfmtVPYUdBJKgmbED9wbEIvmo3pN2shGdGB X-Received: by 2002:a17:906:25d1:b0:8b1:3131:76e9 with SMTP id n17-20020a17090625d100b008b1313176e9mr155042ejb.46.1679599993543; Thu, 23 Mar 2023 12:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679599993; cv=none; d=google.com; s=arc-20160816; b=eS6G8aqMtMTNhVOw7NyZ1vkGKxSb+2JdgGmfy/VEiNrax5h3v7hWmjn0Ey1s3DHe93 t8Xca7gVyStA/1Fnone9n5WJg4b1Han2Zgl9XZJZKjdA93fJAHZ58OsEqrNhG/UNG+by +WtjfLxJ19No0R+tu0AcuZdyxmSMQAOIs+ZAqkJSsQLkw+7Bxx+aHS5bm19Pngn304Gb lKKWUaqwQ1yzxCxNd0Ix+o6vz3Izg73c5ChdaeP+xl6zNoxqrv3siJX8ogOAdw586Qoi 7WygE3o9ZN/Zl1DcYnkVNGxObBcd2vfTdZXmOGDO54XLxp7tWjwio4fw05mb2Hj7wfd0 mZGA== 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=HUzZ+YdgqBsEPba1gZv82s6tRaXrtHgBuVCrMt0RUvs=; b=wn27PPiVjaP3Gvi8NlNzBoBClEd9Mz58a0ppLHN4phJEnjftmAjkIi6lzjcGJD0Rfn MssB4sRUQ5gHrM1OoiZl6HnjWvdI3anrf/YSY+NWm+lyDQs1dmAWrJoWaX1eKmQoXuqJ FLnUVd1jffXFdneKTcKJb2jrBBBao/2tAsBx8e6iWYPn+0WWCg12khrMZHfjNYMHyYQE upUWZOC4hcPanABgJozIXXWcJ702jaJ0M1P0cz+OceSAUupCecfxQdYozQ4q9RwNgApB Xa9YiaF7dvOeSOG6pR768nH0CgbE7fuqzIpRUsDp+Wj7IRfya9iLz/ke0B9DET8h5mka /xtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oPfWJo8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a170906828300b008d6b51de6bcsi18627386ejx.32.2023.03.23.12.32.45; Thu, 23 Mar 2023 12:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oPfWJo8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231146AbjCWTai (ORCPT + 99 others); Thu, 23 Mar 2023 15:30:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbjCWTah (ORCPT ); Thu, 23 Mar 2023 15:30:37 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BE6B442; Thu, 23 Mar 2023 12:30:36 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C6C3A1FE14; Thu, 23 Mar 2023 19:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679599834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HUzZ+YdgqBsEPba1gZv82s6tRaXrtHgBuVCrMt0RUvs=; b=oPfWJo8BQMP2bDXkj8yCk4RZz/8dJUjmcrxd1fPXcFXKcbhft+1tUJjWQ+FEZMBUAiKfla Q5bZOvF+fxnz54/4kxRiPZIR7tWmwGD8hB+FslCHu4Zpn2sS1XGii+T8uToFWJ/KvtwllD WAvIfEu6ozAdMQLADb8W9nosUsE7Xj4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 956B1132C2; Thu, 23 Mar 2023 19:30:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5TdRI9qoHGRwLAAAMHmgww (envelope-from ); Thu, 23 Mar 2023 19:30:34 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: Josef Bacik Cc: Jens Axboe , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org, Navid Emamdoost , Michal Kubecek Subject: [PATCH RESEND v3] nbd_genl_status: null check for nla_nest_start Date: Thu, 23 Mar 2023 20:30:32 +0100 Message-Id: <20230323193032.28483-1-mkoutny@suse.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Navid Emamdoost 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 Reviewed-by: Michal Kubecek Link: https://lore.kernel.org/r/20190911164013.27364-1-navid.emamdoost@gmail.com/ --- I'm resending the patch because there was apparent consensus of its inclusion and it seems it was only overlooked. Some people may care about this because of CVE-2019-16089. drivers/block/nbd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 592cfa8b765a..109dccd9a515 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2394,6 +2394,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.40.0