Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935881AbdIYOVk (ORCPT ); Mon, 25 Sep 2017 10:21:40 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:45266 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933355AbdIYOVi (ORCPT ); Mon, 25 Sep 2017 10:21:38 -0400 Subject: Re: [PATCH] apparmor: fix off-by-one comparison on MAXMAPPED_SIG To: Colin King , James Morris , "Serge E . Hallyn" , linux-security-module@vger.kernel.org Cc: linux-kernel@vger.kernel.org References: <20170822215832.5504-1-colin.king@canonical.com> From: John Johansen Organization: Canonical Message-ID: <1a49cc0a-949b-7821-6a32-d0e71a3491ec@canonical.com> Date: Mon, 25 Sep 2017 10:21:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170822215832.5504-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1147 Lines: 33 On 08/22/2017 05:58 PM, Colin King wrote: > From: Colin Ian King > > There is a an off-by-one comparision on sig against MAXMAPPED_SIG > that can lead to a read outside the sig_map array if sig > is MAXMAPPED_SIG. Fix this. > > Detected with cppcheck: > "Either the condition 'sig<=35' is redundant or the array 'sig_map[35]' > is accessed at index 35, which is out of bounds." > > Fixes: c6bf1adaecaa ("apparmor: add the ability to mediate signals") > Signed-off-by: Colin Ian King > --- > security/apparmor/ipc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c > index 66fb9ede9447..5091c78062e4 100644 > --- a/security/apparmor/ipc.c > +++ b/security/apparmor/ipc.c > @@ -128,7 +128,7 @@ static inline int map_signal_num(int sig) > return SIGUNKNOWN; > else if (sig >= SIGRTMIN) > return sig - SIGRTMIN + 128; /* rt sigs mapped to 128 */ > - else if (sig <= MAXMAPPED_SIG) > + else if (sig < MAXMAPPED_SIG) > return sig_map[sig]; > return SIGUNKNOWN; > } > I've pulled this in to apparmor-next