Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1785218ybj; Sun, 22 Sep 2019 11:53:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlJGxFkAOkaScNgLWlMYsCBI+V72qSroK+VJxf7aLttCG2hwIskblY5M1l1t/02jSoWDFm X-Received: by 2002:a05:6402:356:: with SMTP id r22mr30404871edw.254.1569178384363; Sun, 22 Sep 2019 11:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569178384; cv=none; d=google.com; s=arc-20160816; b=P2uvwhj/k3a7c0qbUAnv+Btq0uI5LdGd7RdjEYDZ8fyAHL9h9rSTJkgfhh+tG+eHdh 3WH61QLeUh+ufd53Z9InsXXFOLfIwaqQ2p9YnT0kGXa62UIg/ot1CEobhJ6xXhRVjOle W6Ku9yTBdytkv9Y1T+I9I90R3ASmqIXDCpeFOLeaa6GMjO295Wd1vHcRwK+fO8U/u8p1 SR/teWyKAu8X7pLJuzwJMo9Tuwl3gKxlLu5RA3E4No/nKbwTAPIR7QZVNuiuv6VNRrji k8PXAkI8UC1hdrMi6wYheSMgds+f22FOCqhUWFhs038VYscj34mcuCiqkEMLoJOzv0nA 1iEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=mbDOq9bHMrOUKNLV3G+a+KuEfosvHVXkNEt05v5wPZ8=; b=DLqTb6xL6iXRTzlVQgRRuyWW+LRsgE58TGxnwHi9SISr6ML3YfPJXIGMzaKR2JhEXU sBTdySnTmJ8EfOADeFoxyG8qMWDSjEANwsEluo++CSnIT5G6XKHiN8YVbCkyn4vA+q/F k0RX/06JdWPYJt8r96HqpffN0FziJq+NmjFTYNr6jPbi6vSuhzBhpMUTXHRZNu9lCDLI RMK+6gg8sSUAf22Kfs94O4gLWkF31bsuIMKrzGzeOgWcBW3sST81KXHhXd0sbDIbddj0 er0a65K36a3l0NOH/WFPdTRbgY1aizkBq3TsFGqnmjAgCkOO7QMfhTqr13IQKOnLiGAX /acQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17si3951381ejd.123.2019.09.22.11.52.40; Sun, 22 Sep 2019 11:53:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390247AbfITQHI (ORCPT + 99 others); Fri, 20 Sep 2019 12:07:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387662AbfITQHI (ORCPT ); Fri, 20 Sep 2019 12:07:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51824315C005; Fri, 20 Sep 2019 16:07:08 +0000 (UTC) Received: from asgard.redhat.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61C7B600C6; Fri, 20 Sep 2019 16:07:06 +0000 (UTC) Date: Fri, 20 Sep 2019 18:06:44 +0200 From: Eugene Syromiatnikov To: linux-block@vger.kernel.org, Josef Bacik , nbd@other.debian.org Cc: linux-kernel@vger.kernel.org, Jens Axboe Subject: [PATCH RESEND] nbd: avoid losing pointer to reallocated config->socks in nbd_add_socket Message-ID: <20190920160644.GA15739@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 20 Sep 2019 16:07:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the (very unlikely) case of config->socks reallocation success and nsock allocation failure config->nsock will not get updated with the new pointer to socks array. Fix it by updating config->socks right after reallocation successfulness check. Fixes: 9561a7ade0c2 ("nbd: add multi-connection support") Signed-off-by: Eugene Syromiatnikov Cc: stable@vger.kernel.org # 4.10+ --- drivers/block/nbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index a8e3815..a04c686 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -987,14 +987,14 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, sockfd_put(sock); return -ENOMEM; } + config->socks = socks; + nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL); if (!nsock) { sockfd_put(sock); return -ENOMEM; } - config->socks = socks; - nsock->fallback_index = -1; nsock->dead = false; mutex_init(&nsock->tx_lock); -- 2.1.4