LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 11-08-2009, 01:21 PM   #16
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60

[Log in to get rid of this advertisement]
i thought protected mode only applies to cross segment code/data.
for example you can execute any data that is in the code segment but cannot execute it in the data segment
windows_vista smeezekitty is offline     Reply With Quote
Old 11-08-2009, 02:48 PM   #17
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 457
Thanked: 4
Quote:
Originally Posted by smeezekitty View Post
i thought protected mode only applies to cross segment code/data.
for example you can execute any data that is in the code segment but cannot execute it in the data segment
right
unless the local descriptor table is wrong some how
there is a asm example for writing self modifying code the trick is making the code and data segments overlap by changing the ELF header
linux rob.rice is offline     Reply With Quote
Old 11-08-2009, 03:16 PM   #18
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 6,739
Blog Entries: 2
Thanked: 214
Actually, I think the correct answer is yes it is dangerous, and so is C ... but only if you don't know what you're doing, and if you're not using a real OS. I remember crashing or BSODing Windoze so many times with simple C programs in programming class ... but the thing is, even if you run those same programs on Linux, it won't crash the system, it'll just say 'seg fault' most of the time.
linuxslackware H_TeXMeX_H is offline     Reply With Quote
Old 11-08-2009, 03:55 PM   #19
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60
Quote:
Originally Posted by H_TeXMeX_H View Post
Actually, I think the correct answer is yes it is dangerous, and so is C ... but only if you don't know what you're doing, and if you're not using a real OS. I remember crashing or BSODing Windoze so many times with simple C programs in programming class ... but the thing is, even if you run those same programs on Linux, it won't crash the system, it'll just say 'seg fault' most of the time.
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
windows_vista smeezekitty is offline     Reply With Quote
Old 11-08-2009, 04:05 PM   #20
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 6,739
Blog Entries: 2
Thanked: 214
Quote:
Originally Posted by smeezekitty View Post
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
Oh, most certainly ... and that was punishment enough, trust me. I mean we had to complete the assignment by the end of the class with all this crashing going on. Not to mention that the computers were PII or lower running W 95 or 98, and some were so slow that they were unusable or would crash on their own.
linuxslackware H_TeXMeX_H is offline     Reply With Quote
Old 11-08-2009, 04:06 PM   #21
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,636
Thanked: 18
Quote:
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
Linux: "Oh, it segfaulted, time to fire up gdb"
Windows 9x: "Damn, it BSODed and I just lost my entire environment"

One is clearly orders of magnitude superior than the other.

Last edited by tuxdev; 11-08-2009 at 04:08 PM..
linux tuxdev is online now     Reply With Quote
Old 11-08-2009, 04:46 PM   #22
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 457
Thanked: 4
Quote:
Originally Posted by tuxdev View Post
I believe he's referring to thunks, JIT and such.. Without the NX bit set on a page, you can execute whatever you like on the stack or heap - the processor doesn't really care inherently, it's just memory.
for real mode your right BUT that's not how protected mode works
here is what intel says about how memory access works in protected mode
http://download.intel.com/design/int...ers/exc_ia.pdf
BTW
DOS 7 (windoze 95) was the last O/S to run in real mode

Last edited by rob.rice; 11-08-2009 at 04:49 PM..
linux rob.rice is offline     Reply With Quote
Old 11-08-2009, 05:07 PM   #23
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 1,035
Thanked: 50
Quote:
Originally Posted by rob.rice View Post
well you found a bug in gcc or the kernel
please report your bug to both the kernel and gcc maintainers
the data is being put in to the code segment or the local descriptor
tables are being written wrong

No, I've found a documented feature:

http://www.embeddedrelated.com/group.../show/5031.php ->

<your_function_return_type> __attribute__ ((section (".data"))) <your_function_name>(<your_function_args>);
linuxsuse Sergei Steshenko is online now     Reply With Quote
Old 11-08-2009, 05:59 PM   #24
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60
windows 3.1 was actually protected mode assisted codenamed "386 enhanced mode" where programs could general protection fault but it is also not completly protected mode.
linuxubuntu smeezekitty is offline     Reply With Quote
Old 11-08-2009, 08:17 PM   #25
paulsm4
Senior Member
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 3,318
Thanked: 144
MrCode -

Your question has certain generated a lot of smoke, noise, half-truths and misinformation

And yes, even some genuine wisdom

Anyway, I think you can safely take away from this discussion:

1. No, you probably can't do any more "harm" with assembly than you can with a high-level language.

Software is software. At the end of the day, it makes little difference if it's written in assembly or a higher-level language. If the OS will let you trash the system, then just about any language will let you trash the system. For example, I can show you a .bat file that can trash Windows NT (no kidding!).

One could argue that "languages" like Java, C# and VB.Net give you additional "protection" - precisely because they're MORE than just "languages". They're a "language" (Java, C#, whatever) plus a "virtual machine" (the JVM, or the .Net runtime). And it's the virtual machine - NOT the "language" - that gives you the extra "protection".

2. Yes, "real mode" and "protected mode" are COMPLETELY different environments.

You simply can't compare the behavior of a C program under real-mode DOS with the behavior of the SAME C program under protected mode Windows.

Again: software is software: the C program under real mode is comparable to the ASM program in real mode; and the same for the C program vs ASM program under protected mode.

I encourage smeezekitty to experiment with DPMI. Both DJGCPP and OpenWatcom let you experiment with C/++ real mode vs. C/C++ protected mode:

http://www.delorie.com/djgpp/
http://openwatcom.com/

Protected mode programming is VERY (read: "fundamentally"!) DIFFERENT from real-mode programming.

It doesn't really matter whether the OS is Linux, Windows or even DOS/DPMI, or whether the language is C/C++ or assembly. What DOES matter is that the address expressed in your application is NOT the actual address used by the hardware.

Last edited by paulsm4; 11-08-2009 at 08:23 PM..
paulsm4 is offline     Reply With Quote
Old 11-08-2009, 09:58 PM   #26
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
windows_vista smeezekitty is offline     Reply With Quote
Old 11-09-2009, 05:53 PM   #27
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: openSUSE 11.1; Pebble; PNE-LE; LFS (no book)
Posts: 382
Thanked: 12
As for NX-bit keeping one safe from accidental execution, that's not entirely correct. As an example, return-into-libc is a whole class of BO which functions fine on an NX stack. At the end of the day, you can only do as much or as little harm in C/C++/asm as the system allows you to do. If you are allowed to send a command to format the hdd, you run that risk. If you're allowed to send some kind of wacky overclocking series of instructions which cause your hdd to simultaneously break the speed of light while your monitor flashes the morse code lyrics to boogey fever, thus creating a rift to the 1970s - well.. you get the picture. Seriously, it's very unlikely that you'll accidentally trash your system, but even if you do the worst that happens is you need to reinstall. Most hardware nowadays protects itself pretty well, and as long as said low-level format is recoverable you're just inconvenienced a lot, and more importantly learn "Don't do that"

Anyway, just one perspective.
orgcandman is offline     Reply With Quote
Old 11-09-2009, 07:19 PM   #28
MrCode
Member
 
Registered: Aug 2009
Location: Maryland, USA
Distribution: Ubuntu 9.04 (main), Slackware 13.0, Mint Gloria (in VMs)
Posts: 88
Thanked: 7

Original Poster
Quote:
1. No, you probably can't do any more "harm" with assembly than you can with a high-level language.
I figured, just wanted to make sure, though. I have heard of instances where hardware was damaged because of either poorly-written or buggy software, but I think that would mostly apply to things like embedded systems/firmware.

Quote:
2. Yes, "real mode" and "protected mode" are COMPLETELY different environments.
I'm reading a basic x86/NASM guide (that can be found here), and as I understand it, you really wouldn't want to program in real mode anyway, right? Not unless you were writing for some ancient 286 with 1MB |< of RAM, where you really have no choice...

Quote:
Originally Posted by smeezekitty View Post
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
I know that you can trash your file system using either of those commands (in DOS/UNIX-like systems respectively), I was just curious as to whether actual physical H/W damage could occur from poorly written software, but as others have said, this would be VERY hard to do...

Last edited by MrCode; 11-09-2009 at 07:23 PM..
linuxubuntu MrCode is offline     Reply With Quote
Old 11-09-2009, 07:37 PM   #29
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 457
Thanked: 4
Quote:
Originally Posted by smeezekitty View Post
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
I did a rm -r /usr from / I thought I was in /root/temp
luckily the package manager was in /sbin , I had the install disks
at hand and I figured out what I did before rebooting
linux rob.rice is offline     Reply With Quote
Old 11-09-2009, 08:12 PM   #30
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60
Quote:
I'm reading a basic x86/NASM guide (that can be found here), and as I understand it, you really wouldn't want to program in real mode anyway, right? Not unless you were writing for some ancient 286 with 1MB |< of RAM, where you really have no choice...
real mode has some serious advantaged especially on a single tasking system.
for example:
you can do increadably fast screen writes by writing to B800:0 in real mode but in dos
you have to call a protected mode function that writes it for you, and that time could be significint!
windows_vista smeezekitty is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASM x32 vs ASM x64 Tegramon Programming 3 02-27-2008 03:26 PM
I/O in ASM Mercurius Programming 10 11-16-2006 08:02 PM
Not exactly a newbie, but still dangerous jhenager LinuxQuestions.org Member Intro 2 09-19-2005 03:51 PM
is this dangerous? Kendo1979 Linux - Security 3 05-18-2005 12:31 AM


All times are GMT -5. The time now is 06:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration