01 June 2009

Rant: Microsoft decreases Firefox's security with a forced plugin

Aaarrggh. I am frustrated.

I am somebody who tries to be serious about computer security. Also, I frequently find myself answering questions from friends and family like ``my computer is slow and it seems to be doing a lot of strange things -- can you tell me what is wrong with it?'' This line of questioning nearly always causes my head to throb. The whole state of security on Windoze machines is something that depresses me.

After performing various magic incantations to try to ``fix'' my friends and family's Windoze machines, I always tell my friends and family to stop using Microsoft's Internet Explorer. I look them right in the eye and tell them that I am deadly serious about this -- in my opinion this browser cannot be made to be secure. In fact, I tell them that in my opinion Internet Explorer would be a much better application if, when it first started running, it displayed a splash screen that stated:

Friendly reminder: by running this browser, you are authorizing one or (probably many) more people who most likely reside in eastern Europe or the Far East to be able to run arbitrary code on your machine. These people will be in complete control of your computer. They will be able to steal anything from your computer, and be able to use your computer to mount attacks against other computers. Have fun on the Internet, and thank you for choosing a Microsoft product!

| OK! |

Instead of running Internet Explorer, I tell my friends and family to run Firefox. This is a no-brainer. I mean, let's be clear: Firefox isn't totally secure either but it is The Right Choice for my friends and neighbors. One gentleman that I know thanked me a few months ago for recommending Firefox to him several years ago. He is a total computer neophyte, and from what I have been told, his computer has been acting fine for years, with no viruses or malware installed on it.

Anyways, getting back to my frustration: Microsoft, in their infinite wisdom, has decided to include a Firefox plugin in their Microsoft .NET Framework 3.5 Service Pack 1 update pushed to end-user's computers via Windows Update.

Some representative from Microsoft has explained the ``rationale'' for this decision:
A couple of years ago we heard clear feedback from folks that they wanted to enable a very clean experience with launching a ClickOnce app from FireFox.

Microsoft's actions here are totally crazy.

First of all, I seriously doubt that Microsoft got clear feedback like this.

Second of all, if Microsoft had wanted to publish an addon for Firefox, The Right Place for Microsoft to publish this addon would have been http://addons.mozilla.org/ . Instead of publishing this addon in the proper manner, letting end-users decide for themselves whether they wanted to install this addon or not, Microsoft has shoved this addon down the throats of end-users.

Third, it seems to me that this addon is yet more poorly designed insecure Microsoft crap. In fact, many people (such as myself) who run Firefox run this browser entirely for the reason that totally crazy insecure plugin crap like this hasn't been available for Firefox -- until now.

Fourth, continuing on with the grand nightmare that Microsoft has created here, Microsoft has installed this plugin at the machine level, and has provided no easy way for end-users to uninstall this enormous security problem from their machines. If an end-user wants to uninstall this plugin, they must resort to using the registry editor, which is far from easy.

Basically, here is what I imagine happened recently in Redmond: somebody at Microsoft observed that Firefox is steadily increasing its market share -- it might have even captured 10% of the market by now. This must have worried this in-duh-vidual from Microsoft, which is arguably one of the world's best monopolies. So, what to do about this? Easy! Produce a plugin that gives people all of the same sucky ``user-experience'' and ``security'' as Internet Explorer, and shove it down the throats of all of the people who use Firefox.

Way to go, Microsoft! I, for one, seriously doubt that this company has my best interests in mind with actions like this one.

15 May 2009

I am not a fan of C++ iostreams

I'm one of those people who thinks that C++ can be an acceptable choice for a programming project. Lots of people think that C++ is dead, but I'm not one of them. I'm not a big fan of this language anymore, but it can occasionally be OK. I'm mostly somebody who programs at the level of bits/bytes/protocols/hardware/etc. so a language that lets me program at this level and also give me some OO features is alright in my book.

There are some parts of C++ that I have never liked though. The other day I was reminded of how much I have always disliked C++ iostreams.

...

I've spent the last {long period of time} wrestling with several large libraries, trying to get them all to work together. It has been like wrestling with three grizzly bears, but I don't mind: this is what I do for a living.

Anyways, around two weeks ago, before I got interrupted with something else, I noticed that my current work was dying strangely. I've been working with somebody else's code, and this code uses C++ iostreams, so, in an effort to fit in, I used C++ iostreams too. I think that the code looks somewhat ugly, but that's the way it is.

So, my code was dying strangely, and then I got interrupted for a few weeks. When I finally got back to take a look at my problem, I came to the dim realization that at some point in the program's execution my debugging output just....stopped. However, it was also obvious to me that certain parts of the program were just churning away, working just fine.

Weird.

Before I seriously got started on this project, I modified the entire project's code to compile without any warnings (as usual, this was a hugely efficient use of time...). Also, there were no memory related problems in the codebase. Nothing in the runtime was smashing one of the iostreams-related data-structures, which could explain the root-cause of the program's output just stopping.

Eventually, after a bit of searching around, I figured out what was going on: a part of the program's code (part that I had never really looked at in detail) was printing out some C++ classes with the iostreams library. The problem was that, as part of my modifications, I had some NULL pointers to various things -- and parts of the code were attempting to print these too.

To cut to the chase, can you guess what the following code produces with my platform's C++ implementation? (generic Linux x86_64 box, g++ 4.x.y, program compiles cleanly with "-Wall -pedantic")


#include <iostream>

int main(int argc, char *argv[])
{
     char *p = NULL;

     std::cout << p << std::endl;
}



Answer: my platform's C++ implementation prints ABSOLUTELY NOTHING when it runs this code. This pretty much mimics the problem I was having with my much larger program.

Since we're on the subject, can you guess what this program outputs on my platform? (gcc 4.x.y, program compiles cleanly with "-Wall -pedantic")

 #include <stdio.h>

 int main(int argc, char *argv[])
 {
     char *p = NULL;
 
     printf("%s\n", p);

     printf("Hello World\n");

     return 0;
 }


Answer: this program prints out something completely reasonable.

The thing that bugs me about the behavior of the C++ program is that not only does the iostreams implementation not tell me about the NULL pointer, but this action also seems to corrupt the internal state of the iostreams library itself, thus causing ABSOLUTELY NO SUBSEQUENT OUTPUT. I mean, surely this must be a common enough occurence in the Real World, no? The designers of iostreams must be happy with their type-safe interface to the rest of the thorny things that might go on in any C++ program, but this particular implementation failed in a manner that cost me a couple of hours of debugging time.

(As a side-note: yes, I know quite a lot about the internal plumbing of C++ to understand why an implementation might not print out the code's NULL pointer here -- yeah, yeah, I know, "undefined behavior". Yawn. Just because I understand what might be going wrong here doesn't imply that I am a fan of this behavior)

I'm just not a big fan of C++ iostreams. I much prefer strategic use of the battle-tested and known-to-be-reliable stdio library -- even in C++ code. Maybe iostreams would be a lot more attractive to me if I commonly programmed at a higher layers, but at that point I'd almost certainly favor Java over C++.

06 April 2009

What is so Hard About Parallel Programming? Lots!

Over at JavaLobby, Clay Breshears asks "What is so Hard About Parallel Programming?".

Hmmm. Interesting. I've spent quite a bit of time thinking about this question too. I happened to write my masters thesis on the subject of parallel computation.

I think that Mr. Breshears is obviously a very smart individual, but I disagree with his assertion that:
[...] learning parallel programming is no harder than learning a second programming language.
Let me be clear: I am not violently disagreeing with Mr. Breshears, but let me put it this way: I would suggest that for a reasonably intelligent computer science student, learning a second programming language, on a scale of 1-10, is around a "3" (in terms of difficulty). Now, for this same student to learn parallel programming, I would estimate that, on a scale of 1-10, the amount of difficulty would be a "7".

So, I disagree with Mr. Breshears.

What is my rationale for my disagreement? In my experience, it is often hard to write a serial program to solve a particular problem. I mean, this should be uncontroversial. However, I think that moving from a serial program that solves a given problem to a correct parallel program that solves the same problem requires a paradigm shift. The central part of this transformation does not involve more rote learning of some new programming language's syntax and APIs -- this process requires a completely different way of thinking. It is one thing to hazily understand that an execution unit on a given machine is going to be executing a given routine; it is another thing entirely to be able to grok that multiple execution units on a given machine might be executing the same routine all at the same time.

There is one other thing that this transformation requires as well: a fantastic attention to detail. Coming up with a correct/efficient parallel program that solves a problem means that the programmer has to completely understand the problem at hand (especially the data dependencies). The programmer also has to know the semantics of the parallel programming system that they are using like the back of their hand. This last bit cannot be stressed enough: the number of details involved here can be mind-boggling.

How difficult can it be to come up with a parallel implementation of a serial program? Well, let me answer this question somewhat indirectly. One of the most seductively popular ways to write a parallel program is to use threads and synchronization mechanisms. In fact, threads and synchronization mechanisms aren't just used for parallel programming -- they're also used quite a bit in concurrent systems programming. This is where I spend quite a bit of my time as a software engineer, actually. Over the years, I have seen quite a few problems in real products that have as their root-cause something to do with threads and synchronization primitives. These problems have all been inadvertently created by engineers with at least a few years of industry experience (sometimes much more...). If engineers with this level of experience can get confused and make mistakes in such an environment, what chance does the average college sophomore (as Mr. Breshears suggests) have to use similar technology and create parallel programs? I would humbly suggest that the answer to this question is "not much".

10 March 2009

In Praise of the Old Guys

Gary Roberts, one of my favorite gritty, character players in the NHL, has retired. I'm sorry to see him go. I have been a fan for a long time of Roberts' leadership qualities and everything he brought to the game. You always knew when Roberts was playing that he was giving one hundred percent of his effort towards making sure his team won.

Let's see, with the retirement of Roberts, who is my current favorite old guy in the NHL? This is an easy question for me to answer: Brendan Shanahan. The Devils recently hired Shanahan and he scored a goal in his first game. I swear, the look on his face after he scored the goal was something like "see, kids, scoring goals is easy -- just like riding a bike!". There was clearly no rust on this old guy.

I think that one of my favorite incidents involving Shanahan occured a few years ago when Shanahan got sick of Donald Brashear's antics so Shanahan decided to do something about it. The thing that you need to understand here is that Brashear is one of the most fearsome enforcers in the NHL. He is VERY good at his job (he is also a very interesting person off-ice). So, when Shanahan dropped gloves with Brashear, this was immediately a very interesting event.



The best part of the whole incident occurred right before the fight, when Shanahan told Brashear to remove his helmet, as if he was saying:

Good Sir! I will be striking your head with my fists soon, and I would be grateful to you if you were to allow me to do so without marring your helmet.
Old guys are great.

24 February 2009

Low-Powered But Decent-Performance Linux Boxes

Today I read some cool news: Marvell is offering a $100 wall-wart computer. This seems to be a pretty neat box, with a reasonable amount of RAM, USB 2.0, GbE, and an ARM-flavored CPU. This would definitely make for a workable home NAS or print server box. Very cool stuff.

I am a big fan of low-powered (electrically speaking) computers. A few years ago I began experimenting with a Soekris net4801 box. I wanted a low-powered (~5 watts at 120 volts) machine to use inside my house. My net4801 uses a consumer-grade 2GB CF card for its hard drive, and it runs a customized Linux distro for its OS.

The thing that drew me towards the Soekris box was the fact that it is x86 compatible, and at the time I purchased the box I was in the middle of a stressful project at $DAYJOB in which I was doing a lot of cross-compilation. I didn't really want to come home from a long day at work to do even more cross-compilation... On my net4801 I have installed a package manager, so adding a new package to the box usually just involves installing from a package.

For my purposes, having a low-powered but decent-performance box available for use at home is VERY handy -- much more handy than simply leaving a noisy, power-sucking tower workstation on all the time at home.

One thing is certain: the whole area of low-power/decent-performance computers is a very interesting place right now. I can't wait to see what the future brings.

09 February 2009

Fun With Logging

What is it with logging subsystems? Writing one always seems to bring up the most interesting problems....

One day at $DAYJOB I was called upon to write a logging subsystem. So, I dived in.

In my judgment, the logging subsystem I had to design+implement had to satisfy a number of basic constraints:
  • output redirectable to a file or terminal or syslog
  • configurable so that engineers working on one subsystem could see their own output and ignore the output generated by other subsystems
  • configurable so that several levels of output could be generated...informational....warnings....debug...etc.
  • ability to generate timestamps with output
  • bombproof and reliable
  • portable to a number of systems and compilers
In addition, due to the nature of the project we were working on, I also added a few more features:
  • very high performance
  • ability to log to a circular memory buffer
  • ability to change logfile parameters at runtime
We were implementing a very big system, and we needed all of these features. So, this is what I designed+implemented.

With all of these constraints, the logging subsystem was not everything to everybody. For example, I was under CONSIDERABLE pressure to make this subsystem as efficient as possible, so when it came time to choosing between making the system easy-to-use or ultra-efficient, I had to choose the latter design goal. Still, I was pleased with my efforts. I unit-tested my code, finished my docs, checked it in, alerted my co-workers, and started to work on other things.

My co-workers thought my work was OK and they started using my logging subsystem.

This is when the interesting problems began.

The problem that hit me right away was that now that our SQA staff had logfiles that they could read, when something went wrong in the product (still in its infancy), most of the time the new bug in the bug-tracking system got assigned to me. What was the rationale for this? Answer (paraphrasing) "The product bombed and I saw an error message in the logfile. Kevin owns the logfile subsystem, so I assigned the problem to Kevin". With this logic, I was getting assigned and bothered by dozens and dozens of bugs. I mean, a logfile message could have said "Fatal error in Ralph's code; please contact Ralph if you see this error" and the bug still likely would have gotten assigned to me. It took me several iterations with SQA to address this problem.

At this point SQA understood that if they wanted to test out my code, they would have to test the logging system ITSELF and not simply look at the messages that happened to be traversing through it. Well, the next test that came up went like this: pump as much {stuff} through the logging system to see it it could handle this. I was a bit dubious of this test, but I had little time to complain. After a week of SQA staying out of my hair, I again started getting many bugs assigned to me. This time the logic went like this: after turning on full logging in every subsystem, heavily loading the system, and then letting it run for a day the system bombed. Oh, and the system was completely out of disk space too, due to the immense size of the resulting logfile.

I had to roll up my sleeves and investigate this situation. It turns out that my code was not the culprit here either, because my code deliberately did not check the return value from the call to write() to send the data to disk. However, now I was getting assigned lots of bugs that had the following pattern: (1) turn on full logging (2) hammer on system for long time (3) observe that it bombs. I did not enjoy getting assigned these sorts of bugs, so I protested to SQA that they were assuming that there was a causal relationship between two things: the fact that the system's disks were filling up and the fact that the system died. I pointed out that these two things might be completely unrelated. Eventually, I had to make this point crystal clear to SQA by writing a tool for them that filled the local disk to 99.999% full before they tested the system. At this point, with a bit of effort, I was able to convince them that if the system didn't die right away when they started their testing, that the problem must lie somewhere else. Eventually, I sat down in the lab for a few hours to figure out where the real root cause was, and sure enough, there were several real problems elsewhere.

The last problem I had with the logging subsystem was the weirdest one. My boss's boss had heard of all of the "problems" that were cropping up "in the logging subsystem" and he decided to see what was going on. I explained the situation with the previous two "problems" to him and he understood right away -- he was, after all, a very good engineer. But then over the next few weeks he asked me several times if I was sure that the logging subsystem was efficient enough. In response to his first few queries as to whether the logging subsystem was "efficient enough" I gave some short but succinct answers: "yeah, it is written very efficiently" and "I used some preprocessor hacks to precompute things", etc. But he kept on asking me about the logging subsystem, and I began to detect a very worried vibe from this gentleman.

The final straw came one day when, for the Nth time, I had to explain that if somebody were to turn on full logging on the system (and you might as well include a few calls to fflush() and fsync() in here, because I made these configurable too), then the system would run slower AND THIS WAS OK. I kept on fielding questions and concerns from various people in the company about this issue, and it was starting to drive me a little bit batty. I'd explain it this way "look, if you ask a computer to do more work, would you also reasonably expect that it would take more time to do this work?". After I managed to extract an answer of "yes" I'd ask "so why are you concerned about our system slowing down if you turn on full debug logging?". I'd also point out that you would NEVER want to do this on a production system.

Anyways, my boss's boss stopped by one more time to ask me about all of this and so I had it out with him. We went back to his office and I explained exactly how the logging subsystem worked and answered all of his questions. Then I got to ask my question: "why are you so concerned about the system running slower when somebody turns on debug logging?". At this point he told me one of HIS war stories: one day when he was working in the telecom world he was involved in a sales demo of a serious, big-iron telephone switch. Not having one of these just laying around for a demo, they brought the potential customer to the central office, where a big-iron switch was operating in a production environment. Well, the demo started, and at one point the potential customer asked "What if something goes wrong on the switch? Are there any debugging capabilities?". Well, the sales engineer, wanting to make a sale said "No problem! I know how to turn on debug output!" and before anybody could stop him he did exactly that. Well, at this point, operations on the switch screeched to a crawl and THIRTY-FIVE THOUSAND PHONE CALLS WERE DROPPED INSTANTLY. He didn't tell me if they got the sale or not.... (I can only assume that this event was the inspiration behind the "can you hear me now!?" slogan)

Anyways, after telling me this, I understood where my boss's boss was coming from. I never got to make any modifications the logging subsystem based on his input (like, maybe some level of debug logging should not be available in a production build) because the issue never really got to be really important and I transitioned to another project a short time later. But, I understood where he was coming from.

Ahh...logging subsystems....never a dull moment.

02 February 2009

Patch for Unix Network Programming Interface Code

I am a big fan of the book _UNIX Network Programming_ by Rich Stevens. Maybe if you are reading this blog you are too.

Anyways, I have discovered that some of the code in this book is suffering from some bit-rot. Specifically in section 17.6 of the third edition some code is presented that allows the programmer to traverse the list of network interfaces on the local machine. This code uses uses ioctl(...., SIOCGIFCONF, ...) to get the information.

The source of the bit-rot is that Stevens' code made some assumptions about the size of (struct ifreq).....and these assumptions are no longer valid, at least, not for me who is running a relatively modern Linux 2.6 box.

So, I've come up with a patch. I'm pretty pleased with my patch, because

  1. the code can be fixed.
  2. the code can be simplified.
  3. the code can be made to be more portable and to still work even if this union is changed in the future.
I thought that other people would find this to be useful as well, so here it is.