From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751372AbdH2T5q (ORCPT ); Tue, 29 Aug 2017 15:57:46 -0400 Received: from mga04.intel.com ([192.55.52.120]:23161 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbdH2T5o (ORCPT ); Tue, 29 Aug 2017 15:57:44 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,445,1498546800"; d="scan'208";a="1212135337" Message-ID: <1504036657.25945.153.camel@linux.intel.com> Subject: Re: [PATCH][serial-next] serial: 8250: don't dereference em485 until it has been null checked From: Andy Shevchenko To: Colin King , Greg Kroah-Hartman , Jiri Slaby , Phil Elwell , Jan Kiszka , Eric Anholt , Thor Thayer , Rafael Gago , David Lechner , linux-serial@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 29 Aug 2017 22:57:37 +0300 In-Reply-To: <20170829165815.23429-1-colin.king@canonical.com> References: <20170829165815.23429-1-colin.king@canonical.com> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-08-29 at 17:58 +0100, Colin King wrote: > Currently, the pointer em485 is dereferenced to get p and then later > em485 is checked to see if it is null before calling __start_tx. In > the case where em485 is null, we get a null pointer dereference. Fix > this by moving the deference and the associated spinlock/unlocks on > p to the code block where em485 is known to be not null. >  static enum hrtimer_restart serial8250_em485_handle_start_tx(struct > hrtimer *t) >  { >   struct uart_8250_em485 *em485; > - struct uart_8250_port *p; >   unsigned long flags; >   em485 = container_of(t, struct uart_8250_em485, > start_tx_timer); > - p = em485->port; >   > - spin_lock_irqsave(&p->port.lock, flags); >   if (em485 && >       em485->active_timer == &em485->start_tx_timer) { > + struct uart_8250_port *p = em485->port; > + > + spin_lock_irqsave(&p->port.lock, flags); Can you describe, please, what on your opinion is protected by this lock? >   __start_tx(&p->port); >   em485->active_timer = NULL; > + spin_unlock_irqrestore(&p->port.lock, flags); >   } > - spin_unlock_irqrestore(&p->port.lock, flags); >   return HRTIMER_NORESTART; >  } >   -- Andy Shevchenko Intel Finland Oy