From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754979AbbHLPRM (ORCPT ); Wed, 12 Aug 2015 11:17:12 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59013 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753268AbbHLPRJ (ORCPT ); Wed, 12 Aug 2015 11:17:09 -0400 Date: Wed, 12 Aug 2015 08:17:07 -0700 From: Greg Kroah-Hartman To: Kang Yin Su Cc: Alexander Shiyan , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] serial: max310x: Fix out of bounds access Message-ID: <20150812151707.GB12397@kroah.com> References: <1439364125-19422-1-git-send-email-cantona@cantona.net> <1439372765.705411926@f362.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23+102 (2ca89bed6448) (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 12, 2015 at 07:50:25PM +0800, Kang Yin Su wrote: > On 12 August 2015 at 17:46, Alexander Shiyan wrote: > >> Среда, 12 августа 2015, 15:36 +08:00 от cantona : > >> > >> > >> added Alexander Shiyan < shc_work@mail.ru >. > >> > >> On 12 August 2015 at 15:22, Su Kang Yin < cantona@cantona.net > wrote: > >> >Max310x driver supports up to 4 UART devices but array size of > >> >"struct max310x_one" is set to 1. That leads to out of bounds > >> >access on UART port registration. > >> > > >> >This patch fixed it by increase the array size to 4 which is > >> >maximum supported UART. > >> > > >> >Signed-off-by: Su Kang Yin < cantona@cantona.net > > >> >--- > > ... > > > > This seems incorrect. The number of ports is allocated dynamically by: > > ... > > /* Alloc port structure */ > > s = devm_kzalloc(dev, sizeof(*s) + sizeof(struct max310x_one) * devtype->nr, GFP_KERNEL); > > ... > > > > Thanks. > > > > --- > > > > > Oh, my bad. But it looks confusing. So we must ensure "struct > max310x_one p[0]" must the last element of "struct max310x_port". Yes, that is a very common pattern we use in the kernel.