diff mbox

[v3] efifb: prevent null-deref when iterating dmi_list

Message ID 1380732219-5458-1-git-send-email-dh.herrmann@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Herrmann Oct. 2, 2013, 4:43 p.m. UTC
From: James Bates <james.h.bates@gmail.com>

The dmi_list array is initialized using gnu designated initializers, and
therefore may contain fewer explicitly defined entries as there are
elements in it. This is because the enum above with M_xyz constants
contains more items than the designated initializer. Those elements not
explicitly initialized are implicitly set to 0.

Now efifb_setup() loops through all these array elements, and performs
a strcmp on each item. For non explicitly initialized elements this will
be a null pointer:

This patch swaps the check order in the if statement, thus checks first
whether dmi_list[i].base is null.

Signed-off-by: James Bates <james.h.bates@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
v3: fixes the "Author" field and James' email address

 drivers/video/efifb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

David Herrmann Oct. 19, 2013, 10:40 a.m. UTC | #1
ping

On Wed, Oct 2, 2013 at 6:43 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
> From: James Bates <james.h.bates@gmail.com>
>
> The dmi_list array is initialized using gnu designated initializers, and
> therefore may contain fewer explicitly defined entries as there are
> elements in it. This is because the enum above with M_xyz constants
> contains more items than the designated initializer. Those elements not
> explicitly initialized are implicitly set to 0.
>
> Now efifb_setup() loops through all these array elements, and performs
> a strcmp on each item. For non explicitly initialized elements this will
> be a null pointer:
>
> This patch swaps the check order in the if statement, thus checks first
> whether dmi_list[i].base is null.
>
> Signed-off-by: James Bates <james.h.bates@gmail.com>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
> ---
> v3: fixes the "Author" field and James' email address
>
>  drivers/video/efifb.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
> index 7f9ff75..fcb9500 100644
> --- a/drivers/video/efifb.c
> +++ b/drivers/video/efifb.c
> @@ -108,8 +108,8 @@ static int efifb_setup(char *options)
>                         if (!*this_opt) continue;
>
>                         for (i = 0; i < M_UNKNOWN; i++) {
> -                               if (!strcmp(this_opt, efifb_dmi_list[i].optname) &&
> -                                   efifb_dmi_list[i].base != 0) {
> +                               if (efifb_dmi_list[i].base != 0 &&
> +                                   !strcmp(this_opt, efifb_dmi_list[i].optname)) {
>                                         screen_info.lfb_base = efifb_dmi_list[i].base;
>                                         screen_info.lfb_linelength = efifb_dmi_list[i].stride;
>                                         screen_info.lfb_width = efifb_dmi_list[i].width;
> --
> 1.8.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tomi Valkeinen Oct. 29, 2013, 10:42 a.m. UTC | #2
On 02/10/13 19:43, David Herrmann wrote:
> From: James Bates <james.h.bates@gmail.com>
> 
> The dmi_list array is initialized using gnu designated initializers, and
> therefore may contain fewer explicitly defined entries as there are
> elements in it. This is because the enum above with M_xyz constants
> contains more items than the designated initializer. Those elements not
> explicitly initialized are implicitly set to 0.
> 
> Now efifb_setup() loops through all these array elements, and performs
> a strcmp on each item. For non explicitly initialized elements this will
> be a null pointer:
> 
> This patch swaps the check order in the if statement, thus checks first
> whether dmi_list[i].base is null.
> 
> Signed-off-by: James Bates <james.h.bates@gmail.com>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
> ---
> v3: fixes the "Author" field and James' email address
> 
>  drivers/video/efifb.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
> index 7f9ff75..fcb9500 100644
> --- a/drivers/video/efifb.c
> +++ b/drivers/video/efifb.c
> @@ -108,8 +108,8 @@ static int efifb_setup(char *options)
>  			if (!*this_opt) continue;
>  
>  			for (i = 0; i < M_UNKNOWN; i++) {
> -				if (!strcmp(this_opt, efifb_dmi_list[i].optname) &&
> -				    efifb_dmi_list[i].base != 0) {
> +				if (efifb_dmi_list[i].base != 0 &&
> +				    !strcmp(this_opt, efifb_dmi_list[i].optname)) {
>  					screen_info.lfb_base = efifb_dmi_list[i].base;
>  					screen_info.lfb_linelength = efifb_dmi_list[i].stride;
>  					screen_info.lfb_width = efifb_dmi_list[i].width;
> 

Thanks, queued for 3.13.

 Tomi
diff mbox

Patch

diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index 7f9ff75..fcb9500 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -108,8 +108,8 @@  static int efifb_setup(char *options)
 			if (!*this_opt) continue;
 
 			for (i = 0; i < M_UNKNOWN; i++) {
-				if (!strcmp(this_opt, efifb_dmi_list[i].optname) &&
-				    efifb_dmi_list[i].base != 0) {
+				if (efifb_dmi_list[i].base != 0 &&
+				    !strcmp(this_opt, efifb_dmi_list[i].optname)) {
 					screen_info.lfb_base = efifb_dmi_list[i].base;
 					screen_info.lfb_linelength = efifb_dmi_list[i].stride;
 					screen_info.lfb_width = efifb_dmi_list[i].width;