Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp457790ybi; Thu, 30 May 2019 01:09:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYuWd2DAwAAIuWa3iDTUgeWm4ycpRJdiUNr0d/9fWjV6HfTwyLsIwoS08Hz0NW7shRFIPe X-Received: by 2002:a17:90a:fa08:: with SMTP id cm8mr2341310pjb.115.1559203763353; Thu, 30 May 2019 01:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559203763; cv=none; d=google.com; s=arc-20160816; b=P5c1t80J+C/ta8MyEKwV+GS3uDG+vq6WFOcveWqfqahpjmRWco2obAIYbxRPfuEkrw I379s/OZyrldsKvWiHHQwh7TIzsjUEByqroigROkSUaD8IPlyuX/iB03SJAmu8dO515D 8jIj2VxuV4EPypiEtrEku/yfhQ6fpoWh5ZfONGzwWMxbHD6T43VIMHCwc2VKDXXaJ64X HMqxDAXICapuGtZ5ge90ulo7TZ8kmnVTUPQegyYcELZaEEzekZ1V3TgYcFtkCBizArHU GYqaJNerhwwxUJKm3snXMjSTIQ7RULgPTrBiHOGC5v19EBHx9rEzvx/OVEnAUfH/Q6OR jIaA== 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:dkim-signature; bh=dmxH8nCXC6gew7umBGLpr9b8q0p2yrRmO5r/LI2MlsI=; b=hoYdEpGAoB9Omki9O0UCvnYTbv/wa+d6g+YCtI6VqYVY9yrqTRWU+qkVq39B+7ymw5 LtfV2mtJqxCOSZJqL+gSiagNqwe58lv1VNtPdSsqUoPZRFvUwk0osnuxYYlwyGCTJOda 5cVL0oNoUIHVh1aK+XIvPJdPQ8l+owgQIBHa7xLz/KeLVdUYAXlB5O2sSw7Mndt9l7YK zZXO4VnLocQYOxqgSR7rcEQx6fc6sCWQdEEzH5IUi/UlUrVXMSZrb/k/cWExeCRbgo8c GCzA49vRtsg7TxyX7oH0t3ob+5VmNh9FPFGTy9myaMlfrWdH8Dwrz5rjlIMV3fxq11hX W1ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cH79pGEo; 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 u8si2219693pjb.34.2019.05.30.01.09.04; Thu, 30 May 2019 01:09:23 -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=cH79pGEo; 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 S1727975AbfE3IGQ (ORCPT + 99 others); Thu, 30 May 2019 04:06:16 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:32874 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbfE3IGQ (ORCPT ); Thu, 30 May 2019 04:06:16 -0400 Received: by mail-pf1-f193.google.com with SMTP id z28so3470652pfk.0; Thu, 30 May 2019 01:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=dmxH8nCXC6gew7umBGLpr9b8q0p2yrRmO5r/LI2MlsI=; b=cH79pGEoPjeUd3cqBNWIUrNpLt+motW/jO41ztMuuj7NLJDf7oLvFWizrvo2R+Sn6D /sg3HuSYb69+snkJuZQhvZD59djGWBaTI9Sk3NmMOtZZKUgitunUvwkp9YNLeZAD4nbj OMm/oLy5DAmE3xOQbOmOTwS/HUZGEmG8mZvU4iEKmBs+JloEQRNU9YUPO900b9TEk1JQ FCJCdrl9fQncvMkV0EH9DXQN9/az/dHgNXxdddbD59tT47Km6LLKsXoctecwUpPJKls3 Z/PIRyoogssp9c0PN+xrQEfz3lBZufIhtLGKzhfjZvgFEukEphGEX/pAuZkRKlXBusd/ Bhug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=dmxH8nCXC6gew7umBGLpr9b8q0p2yrRmO5r/LI2MlsI=; b=OV1LhIpUvyga+IAMvhG56OxZAmTduJltt5rLebJp/MF1iyX7tCCxUlqhHwTPtqijqz 3jQzt66Ac64KxyCLLaKeE0uLXQHWLRXiqoPZnproDF78vGqr2TpJenpP6z7iI0rINDrk auEPPNCrcEqn+J7+uhM2MRxli5CSMgjm+JTXON68O0vsyjWJH3RuS5GP/PMNiiRk7t8P BJ0a21ppHYnsaRButKhvVDfkATV/IL3nJPECoU/+Q5ZKGijbv7GpXYGh3Tc4tmrH0PV2 Fl+uw/8ReITZBE7PzAtgz8IvdV4iUL8erNeRuHy8w/hnQs7H5Z2I2NGpmGGixwu9tm7n umJg== X-Gm-Message-State: APjAAAVOFD/fT9hzSDQbr1eQDrSWMrPTkHPBqSlLXdc8aILDcL/syEnv EN7jCJ595DlwJHJebpuwI13lL4Iy1VI= X-Received: by 2002:a63:1622:: with SMTP id w34mr2579127pgl.45.1559203575735; Thu, 30 May 2019 01:06:15 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id x16sm1928024pff.30.2019.05.30.01.06.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 01:06:15 -0700 (PDT) Date: Thu, 30 May 2019 16:06:02 +0800 From: Gen Zhang To: paul@paul-moore.com, sds@tycho.nsa.gov, eparis@parisplace.org, ccross@android.com Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH] hooks: fix a missing-check bug in selinux_add_mnt_opt() Message-ID: <20190530080602.GA3600@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In selinux_add_mnt_opt(), 'val' is allcoted by kmemdup_nul(). It returns NULL when fails. So 'val' should be checked. Signed-off-by: Gen Zhang --- diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 3ec702c..4797c63 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len, if (token == Opt_error) return -EINVAL; - if (token != Opt_seclabel) - val = kmemdup_nul(val, len, GFP_KERNEL); + if (token != Opt_seclabel) { + val = kmemdup_nul(val, len, GFP_KERNEL); + if (!val) + return -ENOMEM; + } rc = selinux_add_opt(token, val, mnt_opts); if (unlikely(rc)) { kfree(val);