Patch for fbcon not letting to read console font if it's width is 17-24 (3 bytes pitch)

Sokalski, Marcin msokalski at novomatic-tech.com
Thu Feb 10 14:30:57 UTC 2022


staging: drivers: video: fbdev: core: fbcon: Fix getting font from fbcon

The patch fixes the problem of getting fonts from fbcon when the font's
width spans over 3 bytes.
The bug can be reproduced inside linux console running fbcon in following
way:

Set font with width in range 17-24, ie: solar24x32.psfu can be downloaded
from kbd package
> setfont /usr/share/consolefonts/solar24x32.psfu

Try to read it back:
> setfont -O font.psfu

Before the fix, it will diplay:
> get_font: GIO_FONT: Invalid argument

On patched kernel it will output font.psfu file
Now we can confirm it is a valid font file:
> setfont font.psfu

Signed-off-by: Marcin Sokalski <msokalski at novomatic-tech.com>

diff --git a/drivers/video/fbdev/core/fbcon.c
b/drivers/video/fbdev/core/fbcon.c
index 99ecd9a6d844..1f599872cae5 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -1806,18 +1806,15 @@ static int fbcon_get_font(struct vc_data *vc,
struct console_font *font)
  fontdata += j;
  }
  } else if (font->width <= 24) {
- if (font->charcount * (vc->vc_font.height * sizeof(u32)) >
FNTSIZE(fontdata))
+ j = vc->vc_font.height * 3;
+ if (font->charcount * j > FNTSIZE(fontdata))
  return -EINVAL;

  for (i = 0; i < font->charcount; i++) {
- for (j = 0; j < vc->vc_font.height; j++) {
- *data++ = fontdata[0];
- *data++ = fontdata[1];
- *data++ = fontdata[2];
- fontdata += sizeof(u32);
- }
- memset(data, 0, 3 * (32 - j));
- data += 3 * (32 - j);
+ memcpy(data, fontdata, j);
+ memset(data + j, 0, 96 - j);
+ data += 96;
+ fontdata += j;
  }
  } else {
  j = vc->vc_font.height * 4;

-- 
CONFIDENTIALITY NOTICE
------------------------------------
This E-mail is 
intended only to be read or used by the addressee.The information contained 
in this E-mail message may be confidential information. If you are not the 
intended recipient, any use, interference with, distribution, disclosure or 
copying of this material is unauthorised and prohibited. Confidentiality 
attached to this communication is not waived or lost by reason of the 
mistaken delivery to you.
If you have received this message in error, 
please delete it and notify us by return E-mail or telephone NOVOMATIC 
Technologies Poland Sp. z o.o. +48 12 258 00 50. Any E-mail attachment may 
contain software viruses which could damage your own computer system. 
Whilst reasonable precaution has been taken to minimize this risk, we 
cannot accept liability for any damage which you sustain as a result of 
software viruses. You should therefore carry out your own virus checks 
before opening any attachments.
------------------------------------
NOVOMATIC Technologies Poland Sp. z o.o., Poland, Krakowska 368, 32-080 
Zabierzów
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20220210/175c9129/attachment.htm>


More information about the dri-devel mailing list