On GameSpot: Project Natal: You are the controller!
BNET Business Network:
BNET
TechRepublic
ZDNet

By Jeremy Allison
Posted on ZDNet News: Nov 26, 2007 12:00:00 AM

The opinions expressed here are mine alone, and not those of Google, Inc. my employer.]

Commentary--It hasn't been a good month for my code. Samba, the project I'm responsible for, has had to announce several security flaws. Unfortunately some of them were in code I wrote. I always do a large amount of soul-searching whenever that happens. There's nothing worse than finding out something you were responsible for is the cause of many thousands of people having to waste their time rolling out patches. It always makes me wonder if the time has come to give up this programming lark and end my days peacefully in management, messing up other people's code instead of creating my own.

It's very educational however to look at the causes of the flaws, and try and learn what we can from the bugs and also our reactions to them. Samba is an old program. The initial code was originally written 15 years ago. At that time, modern security problems such as integer wrap (where adding two numbers together can end up with a number smaller than both of them, due to the fixed sizes of integers that processors deal with), or heap overflow vulnerabilities (where overwriting unallocated memory on the program heap can allow a clever attacker to seize control of a program) were unheard of. We knew about buffer overruns (where reading more data into a buffer than was originally allocated for it can cause a security breach) and denial of service attacks, but 1992 was a simpler, less hostile time for network software development. Most initial deployments of Samba were on networks isolated from the main Internet, by technically advanced administrators who knew how to download the source code from the Internet.

The kind of security bugs we get now are much more sophisticated than those that were originally present in the first releases of Samba. We also treat them much more seriously than we used to. In the early days, we (or someone else examining the code) would discover a security problem, and almost immediately we made an announcement of a fixed version. Those were also the days where binary releases of Open Source/Free Software were unknown, as everyone knew how to compile from source code. At least everyone who we were interested in working with did. Our response time for security bugs was usually measured in hours (depending on the timezone of the person reporting the bug). I still remember the first attempt by someone to sabotage Samba with a zero-day exploit posted directly to our mailing list without any warning. Andrew Tridgell (the original author of Samba) was so incensed that he immediately raced to ensure the very next message on the list was the patch for the bug. He succeeded. These days we rarely get zero-day exploits posted openly to lists. The bad guys who discover exploits keep them secret for their own illicit use, and the good guys go through the currently agreed-upon best practice of sending notice to the Samba developers directly (at the mailing address security@samba.org) and work with us in coordinating the announcement of the problem and its fix.

Our response time appears to be much slower these days, even though internally we still usually create an initial fix for the problem within a few hours of seeing the report of the bug. Having Samba Team members in almost all timezones helps with this speed of response. What slows us down these days is our own success. In order to responsibly release a security fix version of Samba we must coordinate with a large number of vendors who are reselling and shipping our code. Most of them have their own patch release schedule and internal security teams who validate the suggested patch and agree on a time to announce the vulnerability to everyone.

Who discovers our security bugs? These days, it's about 50-50 between internal audits by the Samba Team and other Open Source security people and external security researchers, who make their money winning contracts by proving how smart they are by discovering vulnerabilities in Open Source/Free Software projects. The way we respond has changed also. What we do now on seeing a security bug is immediately audit the entire code-base to discover if there are any similar problems, or even similar coding practices that might cause future problems, and re-write or remove all such code. It takes longer, but is much safer in the long run. If you examine parts of the Samba code you'll find common functions that are known to be insecure simply won't compile if added to our code. A set of automated macros warns of any use of known bad functions. Still, we can't depend on automation for protection. Our current security vulnerabilities involve exploiting an assumption in one part of the code to cause a vulnerability in what appears to be a completely separate part of the code, which is actually interdependent. Attackers and security researchers are very clever these days.

Is it easier to find and fix security bugs in Open Source/Free Software code rather than proprietary code? My personal feeling on that is "yes". Being able to examine the intent of the author by looking at the code and comments makes it much easier to see where the intent and the code don't match. That's where the security bugs live. Is Open Source/Free Software code safer than proprietary code? I'd say "yes" to that also. Looking at the number of vulnerabilities is misleading. A good 50 percent of our security bugs are found by our own internal code audits, or someone just looking over some code they're working on and saying to themselves "that looks funny..." Whenever we find something like that, we have to report it to the our vendor community and make a security announcement. It is painful doing this but as all our processes are open we don't have the luxury of silently fixing something and hoping no one will ever notice. Proprietary vendors do have that luxury; they would be insane not to take it, and I'm sure they do. Proprietary code vendors need all the help they can get competing with good Open Source/Free Software.

Samba is still written in C. I've examined the possibility of moving to C++, but to be honest that won't really help for the kind of security bugs that we seem to suffer from. In fact by hiding interdependencies in object classes it may make them more difficult to find. Also I'm not the final decision maker on that and many of the Samba Team hate C++ (Luddites that they are :-). Re-writing in a managed code language like Java or C#.NET would definitely help reduce our security problems but would reduce the performance that people find to be one of the compelling reasons to use Samba. It's no accident that none of the competing CIFS servers are written in managed code either. It would cost us six months to a year to re-write everything and get back to the same level of features, probably with reduced performance. We simply don't have the people or time to do that. For the moment we're stuck with C and we have to make the best of it. If someone is creating a competing Open Source/Free Software CIFS server I'd encourage you to do so in a managed code language as an experiment. If it works as well as I'd hope, we may throw our code away and join you :-).

In order to keep Samba relevant and current with modern practice, we've had to keep re-writing and re-designing core parts of the code. Our upcoming release, Samba 3.2, bears little relation to the original 1992 code and uses modern memory management techniques to avoid heap overflow, buffer overruns and memory leaks, much of which was invented by the Samba Team for internal use. The goal is to keep ourselves secure, as the Samba Team uses Samba for file services ourselves. This is all about scratching our own itch, and helping out everyone else as we do so.

I still feel bad about the mistakes I've made, but I try and redeem myself by using them as examples of how not to write code when I do interviews here at Google. If someone doesn't see the bug it always makes me feel better, but acts as a black mark against them in the interview score. After all, everyone we hire should be able to write code better than me :-). The code is out there to be studied; so learn from my mistakes and don't end up having to coordinate a security announcement. That's one learning experience it's better not to have.


Jeremy Allison is one of the lead developers on the Samba Team, a group of programmers developing an open source Windows compatible file and print server product for UNIX systems. Developed over the Internet in a distributed manner similar to the Linux system, Samba is used by all Linux distributions as well as many thousands of corporations worldwide. Jeremy handles the co-ordination of Samba development efforts and acts as a corporate liaison to companies using the Samba code commercially. He works for Google, Inc. who fund him to work full-time on improving Samba and solving the problems of Windows and Linux interoperability.

SponsoredWhite Papers, Webcasts, and Downloads

  • Talkback
  • Most Recent of 113 Talkback(s)
THANKS
I just want to say THANKS. I've been replacing Windows for file/print services with Samba since 1998. I have not had any problems with Samba - security or otherwise.


I'm still amazed that pe... (Read the rest)

Posted by: AldoWatts Posted on: 11/30/07 You are currently: a Guest | | Terms of Use
Great article  markkerzner | 11/26/07
Code snippet  _dietrich | 11/26/07
Re: Code snippet  JeremyAllison | 11/26/07
Could you give us a list of your banned functions? I am sure you are also  DonnieBoy | 11/26/07
list  JeremyAllison | 11/26/07
Thanks, but, I am suprised you do not also ban strncpy(), as it does not  DonnieBoy | 11/29/07
Rebutting himself  Anton Philidor | 11/26/07
Its a silly argument at best.  No_Ax_to_Grind | 11/26/07
Chill out, No_Ax  JeremyAllison | 11/26/07
Great Article And Don't Mind No-Axe  BanjoPaterson | 11/26/07
LOOK EVERYONE!!!@#~!~! HE MENTIONS ME!!@#@#!  Loverock Davidson | 11/26/07
Don't even have to complement Loverock  John L. Ries | 11/26/07
He's a bit like Vogon Poetry  BanjoPaterson | 11/27/07
Oh Spank  Shelendrea | 11/26/07
I allways thought that was a great trick! (nt)  GuidingLight | 11/26/07
What a...  xuniL_z | 11/27/07
But it is not his argument  Richard Flude | 11/26/07
Wow...  jasonp@... | 11/26/07
Soon enough  Yagotta B. Kidding | 11/26/07
Hard to kid a kidder.  SpikeyMike | 11/26/07
Shut Up Old Fool  itanalyst | 11/26/07
Perhaps if he spent less time whining about Microsoft...  ye | 11/26/07
Amazing!  John L. Ries | 11/26/07
Have you ever used Samba?  SpikeyMike | 11/27/07
I thought stealing another's code was frowned upon  xuniL_z | 11/28/07
You don't know the history of SMB...  JeremyAllison | 11/28/07
His specialty seems to be  Ole Man | 11/28/07
Hey Jeremy, I did Learn before I posted. You left out the whole story.  xuniL_z | 11/29/07
You should just stick with Microsoft and not worry about Open Source  Ole Man | 11/27/07
You should just stick with Open Source and not worry about Microsoft  xuniL_z | 11/28/07
Yep, proud of the company I keep  Ole Man | 11/28/07
I thought you'd be  xuniL_z | 11/29/07
it's easy to be fooled  Ole Man | 11/29/07
Easy does it Ole Man  xuniL_z | 11/29/07
Your straw man is not accepted.  Resuna | 11/27/07
Straw man?  xuniL_z | 11/28/07
No blanket statements  Bob.Kerns | 11/28/07
Well put  John L. Ries | 11/26/07
Non-trivial  wadde001@... | 11/26/07
Thanks for the story  John L. Ries | 11/26/07
It's takes a real  Linux User 147560 | 11/26/07
come on LU.  xuniL_z | 11/27/07
"I've always taken claim to my code, good or bad"  Ole Man | 11/27/07
Have you officially  xuniL_z | 11/27/07
Good Lord, Zuny  Ole Man | 11/27/07
I think it's a good thing  xuniL_z | 11/28/07
Begging will avail you of nothing  Ole Man | 11/28/07
Perfect example.  xuniL_z | 11/29/07
Poor Zuny  Ole Man | 11/29/07
I should regret the 139.00 I've spent in the last 7 years  xuniL_z | 11/29/07
Vulnerability counts do matter...  BFD | 11/26/07
code quality study  chemist109 | 11/26/07
Data too narrow, too old.  BFD | 11/27/07
What truly bothers me...  jasonp@... | 11/26/07
I'm in that boat  AbbydonKrafts | 11/27/07
Let me try to address this!  Bob.Kerns | 11/28/07
Nice explanation  Ole Man | 11/28/07
what?  xuniL_z | 11/29/07
Thanks for the professional advice  Ole Man | 11/29/07
I'm sure you do mean the things  xuniL_z | 11/29/07
Part of the problem  alaniane@... | 11/28/07
Revealing. VERY Revealing.  xuniL_z | 11/27/07
Reasoning  SpikeyMike | 11/27/07
Mike. Sorry but you are totally wrong.  xuniL_z | 11/27/07
Riddle me this...  mrOSX | 11/27/07
If you had read my post  xuniL_z | 11/27/07
Actually I took the part about coordinating..  mrOSX | 11/27/07
And you might be right.  xuniL_z | 11/28/07
Credit where due...  kingmph@... | 11/27/07
Ok, nice post.  xuniL_z | 11/28/07
Oh, Boo hoo hoo, poor Zuny  Ole Man | 11/27/07
The cycle of life.  xuniL_z | 11/28/07
The cycle of life.... the fly and the maggot  Ole Man | 11/28/07
you hurt my feelwings.  xuniL_z | 11/29/07
you hurt my feelwings  Ole Man | 11/29/07
Another perfect example.  xuniL_z | 11/29/07
C++  JeremyAllison | 11/27/07
So, what are you waiting for?  xuniL_z | 11/27/07
New project.  JeremyAllison | 11/27/07
Oh, of course mono on Linux......  xuniL_z | 11/27/07
correction. first line was supposed  xuniL_z | 11/27/07
Not illegal to build on Windows...  JeremyAllison | 11/27/07
Why can't everyone state their postion like that. Nicely put!  xuniL_z | 11/28/07
personally I think it's because you're so rude  bmerc | 11/27/07
Can a leopard change his spots?  Ole Man | 11/27/07
Credit where credit is due.  xuniL_z | 11/28/07
To: Ole Man  xuniL_z | 11/28/07
You're quite welcome, Zuny  Ole Man | 11/28/07
Thanks.  xuniL_z | 11/29/07
I agree  alaniane@... | 11/28/07
brutal!  scott1329 | 11/27/07
Not that harsh  JeremyAllison | 11/27/07
Meanwhile the Linux KERNEL  xuniL_z | 11/27/07
Fallacious reasoning again  bmerc | 11/27/07
Not what I said.  xuniL_z | 11/27/07
Of course Vista is more secure  Ole Man | 11/27/07
You have quite an imagination.  xuniL_z | 11/28/07
Mr Ostrich spits the sand out of his mouth  Ole Man | 11/28/07
Nice Rebuttal!!!  xuniL_z | 11/29/07
Better to ask blessings for yourself  Ole Man | 11/29/07
No, it's not better to ask for myself  xuniL_z | 11/29/07
You assume that OSS  alaniane@... | 11/28/07
No assumtions made.  xuniL_z | 11/29/07
You must have a fresh supply of Geritol  Ole Man | 11/29/07
You must have a fresh supply of Geritol.  xuniL_z | 11/29/07
And this coming from the great truth giver  Ole Man | 11/27/07
Thanks  xuniL_z | 11/28/07
Like a rubber ball  Ole Man | 11/28/07
ummmm yeah.  xuniL_z | 11/29/07
Your sad attempts at spirituality and Patriotism  Ole Man | 11/29/07
If you say so Ole Man  xuniL_z | 11/29/07
No one, or no OS should assume its code  Boot_Agnostic | 11/28/07
THANKS  AldoWatts | 11/30/07

What do you think?

advertisement
advertisement

White Papers, Webcasts, and Downloads

SmartPlanet

advertisement
Click Here