From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756814AbbA2TvE (ORCPT ); Thu, 29 Jan 2015 14:51:04 -0500 Received: from [68.232.143.164] ([68.232.143.164]:54551 "EHLO esa2.cray.iphmx.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755696AbbA2TvC (ORCPT ); Thu, 29 Jan 2015 14:51:02 -0500 X-IronPort-AV: E=Sophos;i="5.09,487,1418083200"; d="scan'208";a="200154" Message-ID: <54CA8ED8.5040202@cray.com> Date: Thu, 29 Jan 2015 13:49:44 -0600 From: Frank Zago User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Rickard Strandqvist CC: Oleg Drokin , Andreas Dilger , "HPDD-discuss@lists.01.org" , Greg Kroah-Hartman , "devel@driverdev.osuosl.org" , Linux Kernel Mailing List Subject: Re: [HPDD-discuss] [PATCH] staging: lustre: include: lustre_update.h: Fix for possible null pointer dereference References: <1422557229-3484-1-git-send-email-rickard_strandqvist@spectrumdigital.se> <54CA8CA7.2070403@cray.com> In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/29/2015 01:47 PM, Rickard Strandqvist wrote: > 2015-01-29 20:40 GMT+01:00 Frank Zago : >> On 01/29/2015 12:47 PM, Rickard Strandqvist wrote: >>> >>> Fix a possible null pointer dereference, there is >>> otherwise a risk of a possible null pointer dereference. >>> >>> This was found using a static code analysis program called cppcheck >>> >>> Signed-off-by: Rickard Strandqvist >>> >>> --- >>> drivers/staging/lustre/lustre/include/lustre_update.h | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/staging/lustre/lustre/include/lustre_update.h >>> b/drivers/staging/lustre/lustre/include/lustre_update.h >>> index 84defce..00e1361 100644 >>> --- a/drivers/staging/lustre/lustre/include/lustre_update.h >>> +++ b/drivers/staging/lustre/lustre/include/lustre_update.h >>> @@ -165,12 +165,14 @@ static inline int update_get_reply_buf(struct >>> update_reply *reply, void **buf, >>> int result; >>> >>> ptr = update_get_buf_internal(reply, index, &size); >>> + >>> + LASSERT((ptr != NULL && size >= sizeof(int))); >> >> >> Now size is tested before result. So it could assert if result < 0, while >> the function would have returned before. >> >> >>> + >>> result = *(int *)ptr; >>> >>> if (result < 0) >>> return result; >>> >>> - LASSERT((ptr != NULL && size >= sizeof(int))); >>> *buf = ptr + sizeof(int); >>> return size - sizeof(int); >>> } >>> >> > > > > But if prt is null krachar on the line: > result = *(int *)ptr; > > Maybe there should be two LASSERT then. Yes, that would be safer. Frank.