From patchwork Sat Jan 12 05:31:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10760891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFFED1580 for ; Sat, 12 Jan 2019 05:32:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3E6D2972F for ; Sat, 12 Jan 2019 05:32:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B369B29730; Sat, 12 Jan 2019 05:32:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EBFA2972C for ; Sat, 12 Jan 2019 05:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725831AbfALFcz (ORCPT ); Sat, 12 Jan 2019 00:32:55 -0500 Received: from mta-p8.oit.umn.edu ([134.84.196.208]:54814 "EHLO mta-p8.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbfALFcy (ORCPT ); Sat, 12 Jan 2019 00:32:54 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-p8.oit.umn.edu (Postfix) with ESMTP id 17A54DBA for ; Sat, 12 Jan 2019 05:32:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p8.oit.umn.edu ([127.0.0.1]) by localhost (mta-p8.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id njCG2Ji0bnS6 for ; Fri, 11 Jan 2019 23:32:52 -0600 (CST) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p8.oit.umn.edu (Postfix) with ESMTPS id E116BDB2 for ; Fri, 11 Jan 2019 23:32:52 -0600 (CST) Received: by mail-it1-f198.google.com with SMTP id v188so3788952ita.0 for ; Fri, 11 Jan 2019 21:32:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MqUYBfZHq5DIii1EHKfXy06HQTMznE4WGCEMyyzi+HA=; b=dqFFOt0L7+eQGjVAvluf1lA+QkXkFS+N+jr5bpwAiBRsbmyBV9Ufbhs1LePuWwExLF 5MNTaIlwAft6dONB1NSwV3UXuqCy7CGRnrPW4nF0UuztPWgH1C4vNA6L60SIVuviOjJn b1e4mMdpGXHN0vYdaMGnCOC9zE+khstx9JtWYxQJlMOwLtP6IQPKt2DNZPwAfh4aWUl4 8GAQgCpd3FqwyEZJrpJ1IjZl3vDK/43k6srvuxhcvObEB+W1nHBWNq/kwvuUQIszMcfC GOAC8I4EXhJ73ziHCsTIt7EjOhuJupAIUJ3L5MJi1RaX8CK6siMzw24ciXbRy+fi+GaJ cp2w== 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=MqUYBfZHq5DIii1EHKfXy06HQTMznE4WGCEMyyzi+HA=; b=gxNDkQfM3dyAIitecPbYGdVJufFlZT8NwlZoWpDsQGoqN7oYlX7ewNDUUaCS4hVZc4 Xtanhoqm69YxSgIgVVNAbJ6X7imwO2/1So+Ew4mSHTiFRd2TYOtPNavl33QV3L4mHtU+ PoaNxPFaHjMMY2z6N2lPhkh3LGKIa47VwmZ9C1hL5BMFt9iggRukld18IK/lKPxsnrmX QLSJe8ZjNjO0QJIuIR8MThghrM/SdBhCiv85o4NF20aXrAXD/cVHkYceOCdMDYMgo9e4 6TcttU8vCRj0XdvkKEiH5irt5hA1dJU/3IDupn11S4uhH89KmRfudZRDuvC3pvMYlXwr FvBQ== X-Gm-Message-State: AJcUukfJzNEfYPSq1MzCDHlpWhly+I5cHJKkZH50fj07plo4ROTij9Yi xcMGiW7w6Fo4r+Urp5DL8+jzxDPoQS/j00JESeGibHZ57c6fSB6y/AE5ZtLobWiSc2nH9V4LLFQ yRXiYhLgBDYiNH7aWh/vnrrgw5ZVT X-Received: by 2002:a6b:cc07:: with SMTP id c7mr10578606iog.136.1547271172490; Fri, 11 Jan 2019 21:32:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN5LJUXIvqhT3gqSck75EfMV3sy9WIBji8nDuf7BFPqQXMSYd4LjO7/u40YbmKI0y7iH4X4PNw== X-Received: by 2002:a6b:cc07:: with SMTP id c7mr10578597iog.136.1547271172193; Fri, 11 Jan 2019 21:32:52 -0800 (PST) Received: from localhost.localdomain (host-173-230-104-22.mnmigsc.mn.minneapolis.us.clients.pavlovmedia.net. [173.230.104.22]) by smtp.gmail.com with ESMTPSA id p19sm1956524itp.13.2019.01.11.21.32.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 21:32:51 -0800 (PST) From: Kangjie Lu To: kjlu@umn.edu Cc: pakki001@umn.edu, "Nicholas A. Bellinger" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] target: fix a missing check of match_int Date: Fri, 11 Jan 2019 23:31:59 -0600 Message-Id: <20190112053159.99406-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <5C38F72B.5000203@redhat.com> References: <5C38F72B.5000203@redhat.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When match_int fails, "arg" is left uninitialized and may contain random value, thus should not be used. The fix checks if match_int fails, and if so, returns its error code. Signed-off-by: Kangjie Lu --- drivers/target/target_core_rd.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c index a6e8106abd6f..3b7657b2f2f1 100644 --- a/drivers/target/target_core_rd.c +++ b/drivers/target/target_core_rd.c @@ -559,6 +559,7 @@ static ssize_t rd_set_configfs_dev_params(struct se_device *dev, char *orig, *ptr, *opts; substring_t args[MAX_OPT_ARGS]; int arg, token; + int ret; opts = kstrdup(page, GFP_KERNEL); if (!opts) @@ -573,14 +574,24 @@ static ssize_t rd_set_configfs_dev_params(struct se_device *dev, token = match_token(ptr, tokens, args); switch (token) { case Opt_rd_pages: - match_int(args, &arg); + ret = match_int(args, &arg); + if (ret) { + kfree(orig); + return ret; + } + rd_dev->rd_page_count = arg; pr_debug("RAMDISK: Referencing Page" " Count: %u\n", rd_dev->rd_page_count); rd_dev->rd_flags |= RDF_HAS_PAGE_COUNT; break; case Opt_rd_nullio: - match_int(args, &arg); + ret = match_int(args, &arg); + if (ret) { + kfree(orig); + return ret; + } + if (arg != 1) break;