From patchwork Mon Sep 30 18:54:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11167127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 599E716B1 for ; Mon, 30 Sep 2019 18:59:40 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 412AA224D5 for ; Mon, 30 Sep 2019 18:59:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 412AA224D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id CFCDA5C3B7D; Mon, 30 Sep 2019 11:58:23 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp4.ccs.ornl.gov (smtp4.ccs.ornl.gov [160.91.203.40]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 9A0425C3A7A for ; Mon, 30 Sep 2019 11:57:07 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp4.ccs.ornl.gov (Postfix) with ESMTP id 80475100541F; Mon, 30 Sep 2019 14:56:56 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 7F434BD; Mon, 30 Sep 2019 14:56:56 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Mon, 30 Sep 2019 14:54:49 -0400 Message-Id: <1569869810-23848-31-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1569869810-23848-1-git-send-email-jsimmons@infradead.org> References: <1569869810-23848-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 030/151] lnet: fix memory leak and lnet_interfaces_max X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amir Shehata , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Amir Shehata Free buffer allocated for discover command. Set lnet_interfaces_max to LNET_INTERFACES_MAX_DEFAULT if it's not defined or if it's being set to something below LNET_INTERFACES_MIN. For lnet_ping() and lnet_discover() if the provided space can fit more NIDs than lnet_interfaces_max then ensure only lnet_interfaces_max is copied into the buffer. WC-bug-id: https://jira.whamcloud.com/browse/LU-9909 Lustre-commit: 81d4f7a25319 ("LU-9909 lnet: fix memory leak and lnet_interfaces_max") Signed-off-by: Amir Shehata Reviewed-on: https://review.whamcloud.com/28702 Reviewed-by: Sonia Sharma Reviewed-by: Olaf Weber Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- net/lnet/lnet/api-ni.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/net/lnet/lnet/api-ni.c b/net/lnet/lnet/api-ni.c index 47f4f2a..78fd05f 100644 --- a/net/lnet/lnet/api-ni.c +++ b/net/lnet/lnet/api-ni.c @@ -170,8 +170,8 @@ static int lnet_discover(struct lnet_process_id id, u32 force, if (value < LNET_INTERFACES_MIN) { CWARN("max interfaces provided are too small, setting to %d\n", - LNET_INTERFACES_MIN); - value = LNET_INTERFACES_MIN; + LNET_INTERFACES_MAX_DEFAULT); + value = LNET_INTERFACES_MAX_DEFAULT; } *(int *)kp->arg = value; @@ -3407,9 +3407,15 @@ static int lnet_ping(struct lnet_process_id id, signed long timeout, int rc2; /* n_ids limit is arbitrary */ - if (n_ids <= 0 || n_ids > lnet_interfaces_max || id.nid == LNET_NID_ANY) + if (n_ids <= 0 || id.nid == LNET_NID_ANY) return -EINVAL; + /* if the user buffer has more space than the lnet_interfaces_max + * then only fill it up to lnet_interfaces_max + */ + if (n_ids > lnet_interfaces_max) + n_ids = lnet_interfaces_max; + if (id.pid == LNET_PID_ANY) id.pid = LNET_PID_LUSTRE; @@ -3575,13 +3581,18 @@ static int lnet_ping(struct lnet_process_id id, signed long timeout, int max_intf = lnet_interfaces_max; if (n_ids <= 0 || - id.nid == LNET_NID_ANY || - n_ids > max_intf) + id.nid == LNET_NID_ANY) return -EINVAL; if (id.pid == LNET_PID_ANY) id.pid = LNET_PID_LUSTRE; + /* if the user buffer has more space than the max_intf + * then only fill it up to max_intf + */ + if (n_ids > max_intf) + n_ids = max_intf; + buf = kcalloc(n_ids, sizeof(*buf), GFP_KERNEL); if (!buf) return -ENOMEM;