From: Jan Kara Subject: Re: [PATCH] audit: Fix check of return value of strnlen_user() Date: Thu, 4 Jun 2015 09:36:37 +0200 Message-ID: <20150604073637.GA5923@quack.suse.cz> References: <1433257709-1530-1-git-send-email-jack@suse.cz> <1616713.xG362InQ3V@sifl> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t547ai8i000348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 4 Jun 2015 03:36:44 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (Postfix) with ESMTPS id 650FB376B82 for ; Thu, 4 Jun 2015 07:36:43 +0000 (UTC) Content-Disposition: inline In-Reply-To: <1616713.xG362InQ3V@sifl> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: Paul Moore Cc: linux-audit@redhat.com, Jan Kara List-Id: linux-audit@redhat.com On Wed 03-06-15 14:56:18, Paul Moore wrote: > On Tuesday, June 02, 2015 05:08:29 PM Jan Kara wrote: > > strnlen_user() returns 0 when it hits fault, not -1. Fix the test in > > audit_log_single_execve_arg(). Luckily this shouldn't ever happen unless > > there's a kernel bug so it's mostly a cosmetic fix. > > > > CC: Paul Moore > > Signed-off-by: Jan Kara > > --- > > kernel/auditsc.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index 9fb9d1cb83ce..bb947ceeee4d 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -1023,7 +1023,7 @@ static int audit_log_single_execve_arg(struct > > audit_context *context, * for strings that are too long, we should not have > > created > > * any. > > */ > > - if (unlikely((len == -1) || len > MAX_ARG_STRLEN - 1)) { > > + if (unlikely((len == 0) || len > MAX_ARG_STRLEN - 1)) { > > While we're at it, should we make it just "len > MAX_ARG_STRLEN" as well? > Reading the comments in include/uapi/linux/binfmts.h as well as > valid_arg_len() that seems to be the correct logic. Umm, but audit_log_single_execve_arg() does decrement 1 from strnlen_user() result before doing the comparison. So the current test seems to match the one in valid_arg_len() exactly... Honza -- Jan Kara SUSE Labs, CR