Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp494654ybi; Thu, 30 May 2019 01:54:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5lkeYQS+taLpNlf9sopjc3yAKagy0UHSAD2IYu+hmMFBBgCPKyvsOrWiNzJ+OcDmIzqR1 X-Received: by 2002:a17:90a:1b0b:: with SMTP id q11mr2472371pjq.80.1559206454504; Thu, 30 May 2019 01:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559206454; cv=none; d=google.com; s=arc-20160816; b=IP5Fn+Olkat7eld+eQOUD3CBOEzu1IN3TeoBZ2IcsIipMa86oANGBNKDQP+xihcn6p Frid+VI9IRRZRSLK/9lMCZ8xlUr5hL5CIyBe2kij84AIsKJ3U0ZNk9PbvJd4HOvyp+dv MXA6VjBC4e2eNlgWgZhJyel2dS3AoVBAxQbciGdZRzFfbtBfR8MOFstFchxC7IFO8kqq YS10YngLctSbAij/xdDAQyYPgWfd2Vg5Dp8DJvA1b90aq2VVkLdCxmLN7d7GcyTA7UoS rFb7NZIzDU0rUTAn72NUFKwsMkmye3v7z6FA8wteCjITkG7Fz4mnRBXnao/yNWq7jm1A KM+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9yPNki8tFmIgDjX+2v/i+yBX4YbiShnd6bPfUYaPNcY=; b=wO1OE2Gl7ckzsBHhrTxAxKBSPVwHBZEA6Rv/B+19v77gXchW38CT5G8HDt4GGxBD0F g2kH5atxHR87bw77LXdacd9EU1XFaVrMflUpEPPUF+51RgD8jdEK0rx6B0nqBsC9Bx5M G79z7vL3Fvsq0dF97SJp9ng0LL1WPO55ekAlSOYr4uhRSkx1HvGmNfIZ6rbX2JnDP5tn TZRH1qGVXxfAErpCLYjBafYMWMAY7Oq7gbEV+L3Ffi/5+j43K8DrRxEfeazHimOoMy1R FhR4N20iAZHHHveHZ8G9PK/Atus46fWyHoNlzqyz5KHxampxQSP1iGtlRTNDgARrUsFW K5kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bFXjyuJz; 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 a6si2667333pla.259.2019.05.30.01.53.58; Thu, 30 May 2019 01:54:14 -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=bFXjyuJz; 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 S1726994AbfE3Ivb (ORCPT + 99 others); Thu, 30 May 2019 04:51:31 -0400 Received: from mail-pg1-f173.google.com ([209.85.215.173]:33489 "EHLO mail-pg1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbfE3Ivb (ORCPT ); Thu, 30 May 2019 04:51:31 -0400 Received: by mail-pg1-f173.google.com with SMTP id h17so1637665pgv.0; Thu, 30 May 2019 01:51:30 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9yPNki8tFmIgDjX+2v/i+yBX4YbiShnd6bPfUYaPNcY=; b=bFXjyuJzEziH0nuuB8bYDwiEuyEkZjkBk3ZzpHUpSMKjUkJc5ctwmzPPoENpZjfGcn QF8I2/ImQRSTLJjjiCAP2YDQY65pWycuP2uBDtqLC1AbrfAZVOMutCwt4KZdbBfJvxr6 DvrQZUsDKo3N2h3X0l6CVvmyj9r685BsnPXNFky/0ppnTK76TyBUE+idc9175k1zCLL+ e06KDeKwzf6F5y1aaTmg6A7dAYabxHhGCDAUEOQknBEyXwDPybZ6AilZdIoD+/IqAy8d EVp5FzU1vntuD/LgnzC71HcgqzMhJGNW+BTSzlnKP6aog68gQEu91tYV8idhS1mE+h5j u43A== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9yPNki8tFmIgDjX+2v/i+yBX4YbiShnd6bPfUYaPNcY=; b=PIhXSHTxSpNBc9T9V4XrgTBB6IjjTPEsnPwyMSxQZCnil8/jr+AEF3OVcuZburTTQ9 rr2YiWoqhKUfzvSLhQDhmsGyj3LtQuNYgCPWxVQ7caFxlAvVzVaRxmVwGKH6cfKWS9ek PW65EbwRRO77s9yH91LnxEDM9lO+8XXl7HtXby9qtgNgAkKX6YqKYOS8axuMBXjSNDvX fwFFAqHTgSgAt6pnC3LgZHPpoJr/0jvyH9HYQKmknLcukRBKXVFHy/YVQF1Lc3XSkCIc OLY6WK0K1KwkQ3cv2qJccxp/xXSlI8Huw5gUN6c1aB9fnpHJaZKMgVdGUWuOGxp9pPtn 7fyg== X-Gm-Message-State: APjAAAXWnS0QuESdwizwIriuE5D0A2s/y6Hs87Y9oR5sIEuYejzYhREq lUd0fOaBQKFHSyXWBjxFhOI= X-Received: by 2002:a65:62d8:: with SMTP id m24mr2755254pgv.141.1559206290397; Thu, 30 May 2019 01:51:30 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id q28sm2405694pfn.106.2019.05.30.01.51.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 01:51:29 -0700 (PDT) Date: Thu, 30 May 2019 16:51:06 +0800 From: Gen Zhang To: Ondrej Mosnacek Cc: Paul Moore , tony.luck@intel.com, Stephen Smalley , Eric Paris , selinux@vger.kernel.org, Linux kernel mailing list , bpf@vger.kernel.org Subject: [PATCH v2] hooks: fix a missing-check bug in selinux_sb_eat_lsm_opts() Message-ID: <20190530085106.GA2711@zhanggen-UX430UQ> References: <20190530035310.GA9127@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It returns NULL when fails. So 'arg' should be checked. Signed-off-by: Gen Zhang Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()") --- diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 3ec702c..5a9e959 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2635,6 +2635,8 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts) *q++ = c; } arg = kmemdup_nul(arg, q - arg, GFP_KERNEL); + if (!arg) + return -ENOMEM; } rc = selinux_add_opt(token, arg, mnt_opts); if (unlikely(rc)) {