flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Boot validation

Author
Thread Post new topic Reply to topic
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 13 Mar 2006, 11:10
Hi!

Does anybody have any good idea of how to implement boot-time validation of second-stage loader?

Most boot sectors just look for the fixed name file, load it at some memory area and execute from some fixed address.
But is it good idea to have some very basic protection from having this file corrupted or having wrong file with same name? Should boot loader validate this file before executing it?

Does anybody did anything similar or have any good idea of how this could be smartly done?
Post 13 Mar 2006, 11:10
View user's profile Send private message Reply with quote
kake_zinger



Joined: 15 Jul 2004
Posts: 51
kake_zinger 13 Mar 2006, 11:50
Easy: add all bytes/dwords of the code together, compare sum to precalculated known good value. Or a weighted version of this where each byte value is multiplied with its instruction pointer/location in code before adding up. Better: calculate CRC-32. Just how much validation do you need?
Post 13 Mar 2006, 11:50
View user's profile Send private message Reply with quote
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 13 Mar 2006, 12:31
Well, I already thought about using some kind of checksum. But this method has some disadvantage - when I change something in the second-stage loader (and this will happen often), then I need to change also the boot loader which is something very undesirable.
Post 13 Mar 2006, 12:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Mar 2006, 13:18
well, that's what is boot validation about, no? or just mark proper file/sector with some unusual byte sequence and test for it in boot code.
Post 13 Mar 2006, 13:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 13 Mar 2006, 13:34
Actually, I'm thinking about more OOP-like approach to this problem. Boot sector will contain some fixed piece of code for validation, and all validation data will be contained in checked file. Maybe in some kind of header. When the file content changes - the header changes as well, but the method for validation stays the same.
Post 13 Mar 2006, 13:34
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 13 Mar 2006, 17:02
Some thing like this:
Code:
 use16          ORG   0x**** ; Set your org here         jmp   start  ; jump to start         db    'CODEX' ; ID  ;----------------------------------------------------;   ; Start of program.                                  ;   ;----------------------------------------------------; start:     

Now all you need to do is check for "CODE" .
Post 13 Mar 2006, 17:02
View user's profile Send private message Reply with quote
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 14 Mar 2006, 09:26
Yes, that will guarantee at some level that this is the file I need, but there's still no protection against file corruption (caused by transfer link distortions for example)
Post 14 Mar 2006, 09:26
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 14 Mar 2006, 11:39
Maybe a hybrid with easy checksum + checking for "CODE". By easy I mean just a sum and this can be achieved with macros so you don't need to manually calculate it each time you change something. Its part of the assemblying.

PS. Welcome to the boards - glad to have more Estonians here Wink
Post 14 Mar 2006, 11:39
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 14 Mar 2006, 12:46
I think I will use the same approach as PMInfoBlock structure in VBE 3.0 standart. The file will contain a header with some constant signature, welcome message, file length and checksum. The boot loader will read the first file sector and check for this header, then display the welcome message (containing among other things file version which is subject to change), then load the rest of the file, calculating it's checksum and comparing it with checksum from the file header.

This way I will have a constant boot loader and all information that changes will be placed in the file.

So the structure will look something like this:
Code:
              db    'CodeX'                       ; header signature
              db    39                            ; header length
              db    'Second-stage loader v1.7', 0 ; welcome message
              dd    0xfadecafe                    ; file length
              dd    0xdeadbeef                    ; file checksum (or CRC-32)
              db    0xbc                          ; header checksum
              ;--------------------------------------
              ; Start of program
              ;--------------------------------------
              ...
    


PS. To Madis731: Yes, that is really pleasant surpise Smile
Post 14 Mar 2006, 12:46
View user's profile Send private message Reply with quote
doubletoker



Joined: 15 Mar 2005
Posts: 4
doubletoker 15 Mar 2006, 16:15
the boot loader I'm working on now, looks for a file on fat 12 which is marked read_only hidden system and inside a directory named kernels, I'm in the process of making it, if more then one file has the same attribs then it allows you to select which kernel, also trying the same idea on the boot directory to select which second stage os loader or program to run. the idea here is you can make a batch file that assembles the code, changes the attrib, writes it to the disk, and changes the attribs back, allowing no changing of the boot sec code, just an idea though. I guess my validation would be in a certian directory with the attribs set.

-pz
Post 15 Mar 2006, 16:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.