Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Thursday, June 05, 2014

Smart alarms for when awake and working

The link is vaguely related, but this post was not prompted by it - I just wanted to have some link to the state of the art: Five free apps to help remind you to take a break - TechRepublic:



Like many folks, I sit too much working at my computer.



I have an activity monitor, my Basis Watch.  It tracks how long I sit still.   In the past few weeks, I have still for as long as 4.5 hours at a stretch - that's absolutely still, in my chair at my keyboard, typing.  Nearly every day I sit still for 2 or 3 stretches of 2 hours. Basis allows you to set a goal - "Don't Be A Sitter: from 9-5, get up every N hours."  I currently have the goal set at 2 hours - because whenever I move it lower, say 90 minutes, it gets depressing.



I have tried setting alarms to remind myself to get up and work.  Right now I have alarms set at 11:30, 2:00pm, and 3:30pm. Why so irregular? See below.



This post was prompted by my 11:30 alarm going off.  Unnecessarily, because I had just been active, walking over to a coworker's desk.



Having the alarm go off unnecessarily is irritating.  Having it good just as I am settling back at my desk to get back to work disrupts my concentration, breaks my flow.  Having the alarm go off when I am 30 or 45 minutes into a good working period, into flow, really pisses me off.  I have this theory that interruptions while you are in the middle of a critical b it of work, several things up in the air, in your head, is one of the primary causes of bugs.



What I want is an alarm, a reminder, to get up and move around, that is not at an absolute time.  What I want is an alarm that occurs, say, an hour from the last time I got up and moved around.  An alarm that is smart enough to reset itself



More: I want an alarm, a reminder, that is smart enough to detect (by some heuristic) if I am in flow or not.  (Hmm, I wonder if my Basis watch can reliably distinguish typing.  It's accelerometer is on my wrist, after all.  Since I am a hunt and peck typist, 60wpm, but 80% right handed, I might have to move my watch from left wrist to my right wrist.)



A reminder that is smart enough to try to look for a period to notify me, after I have been working for an hour, but before I have been working for 2.  Looking for a period where I am not working intensely.   Possibly looking fior a period where I am not typing intensely - or possibly looking at what I am actually doing, whether I am working, or in Blogger (like now).    Which is smart enough to look for a good period to interrupt me.  But which might interrupt me no matrter what I am doing after 2 hours of sitting.



You know those prtoducts that try to wake you up at a good point in your sleep cycle? e.g. http://www.sleeptracker.com/how-it-works/



What I want is a product that interrupts me at a good point in my work cycle.



(Ideally it might be smart enough not to interrupt me when I am in a meeting. )



--



Smart alarms when you are awake.



Smart alarms when you are workuing.



Smart alarms should not just be for sleep.


---



(Possibly it could have the sort of incremental alarm feature that a dawn simulator has.  A low priority background notification that ramps up gradually.)





---







OK, I should just go ahead and write it myself.   I installed Tasker for Android to write such scripts. I am not a big fan of Tasker - stupid graphical interface, but worse, my phone battery always drains.   I got the basic timer functionality working, but was not able to detect movement by accelerometer. (Blogging mwe this prompted to re-Google, and I found https://play.google.com/store/apps/details?id=com.kanetik.movement_detection_trial_premium)






Thursday, May 01, 2014

Temporary files, security - and filesystem transactions

It is well known that temporary files can be security holes.

Hence

mkstemp(3)

which generates a unique temporary file name, creates and opens the file, and returns an open file descriptor for the file.

"Atomically".



But this may not be enough.

E.g. today I am trying to replace a file with a new file generated from it - by creating a temporary, and then renaming.



Problem:

* I can't rename the file  specified by a file descriptor

* if I rename the file

   * on Linux, the name may have been reused, since Linux allows files to be removed even though open

   * on cygwin, cannot rename if open. but if I close the handle, then the bad guy may be able to race and intercept



We can discuss kluges for this specific case:

* e.g. rename a file specified by descriptor



But the more general problem is

* atomicity

* and the fact that temporary filenames are globally visible.



If the temporary filename were not globally visible, then could securely



      create tmp

      write tmp

      close tmp

      rename tmp



with confidence that nobody else is squeezing between.



More generally, if we had filesystem transactions to guarantee atomicity



      BEGIN TRANSACTION

      create new file1, file2

      write new file1, file2

      close new file1, file2

       abort if error

     END TRANSACTION



Then we can create multiple such files, without having to mess with temporary filenames,

and without having to rename the temporary filenames to the official filenames.

We can use the official filenames from the get-go.



I.e. filesystem transactions automatically create secure hidden temporary files.

Without error prone programming.



---



The same may apply to shared memory transactions - but is most interesting when the shared memory has fine grain access control, e.g. capabilities, rather than the "shared-memory = security hole" we have nowadays.






Monday, April 28, 2014

The Linux Upgrade Treadmill - Goodbye, Microsoft®

The Linux Upgrade Treadmill - Goodbye, Microsoft®:



'via Blog this'



All software puts us on an upgrade treadmill.



Virtual machines might allow us to run old software that we are happy with.   But then we are just on a maintenance treadmill - upgrading the virtual machine that allows us to run the old software.  Perhaps not so bad if a single virtual machine had all personalities - but inevitably they don't / won't.



Moreover, the biggest reason to upgrade is to gety security patches.  Perhaps don't need to upgrade apps that are not exposed to attackers - but exactly what apps are those?  Open Office... nah.




Tuesday, March 25, 2014

Batch saving files in FrameMaker 11

I just wrote a Framemaker ExtendScript (Javascript dialect) to save all files in a Framemaker book as MIF.



Specifically, MIF7 in my case (hardwired, needs to be configurable).



Needed it because I use Frame 10-11-12, whereas the techwriter who cleans up my English uses Frame 7.   Frame 7 doesn't run on my PC, at least not reliably, whereas her Windows XP PC cannot run a modern FrameMaker.   And the company runs FrameMaker 7 on an old Sun box that is more than 100x slower than a modern PC for many common actions.



So we are stuck converting files between Framemaker binary .f, format and MIF7.



Doing this by hand for 315 files in just one of our architecture specs is a real pain.  I felt a weight lift off my chest when I ran this for the first time.



--



The script only saves .fm files in the .book.  It does not (yet) find all text inset files.



--



Next on the wishlist: batchify this fm2mif and mif2fm, so that Makefiles, etc., can use it.



I do not know how to invoke FrameMaker on a PC with useful command line arguments specifying, e.g. file or book, and command to run.



Can fake things by changing setup files.  That's fragile.



Perhaps can have ExtendScript parse a text file, and evaluate that.  Risky.


Wednesday, March 05, 2014

Byzantine Password Managers

Password managers like LastPass (https://lastpass.com/) - convenient. But risky. ISO a Byzantine password management system. No single password manager storing the actual passwords. Instead, if Byzantine-3, then any 2 have enough information to obtain stored passwords in plaintext - but no single password manager does. Probably requires a Javascript client that accesses each of the Byzantine set, and combines their responses. What does this protect against? => Having one (or a few) of the Byzantine set hacked. But not having a quorum hacked. => The bad guys hacked a sub-quorum do not have the ability to log in. => The bad guys cannot DOS you by giving you bogus data. What does it not protect against? X=> doesn't protect against the most likely security flaw: having the user computer, e.g. web browser, hacked. Wait... about that... ?=> Two+ factor. Clients running on two or more devices, e.g. PC and cell phone. No client knows the actual password? Unfortunately, this would require the folks who require passwords to get involved. Beyond 2 factor. "Dynamic two factor"? (But I guess this is what the security amulet idea is all about.)

goto fail - goto not the problem, lack of else was

ImperialViolet - Apple's SSL/TLS bug:

'via Blog this'
Apple's "goto fail" bug is notorious. Much discussion about how proper unit testing would have found it. Let alone code reviews. (I hope this bug is going into the pattern database for lint-like tools.)

While goto-less programming might have avoided the problem, I think it would have done so at the cost of readability.

I think it is more interesting that the problem might have been avoided if ELSE had been used.  The code in question is really a cascaded set of IFs, where each is only done if all earlier have succeeded - but it is expressed as independent statements.

The buggy code:

static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
                                 uint8_t *signature, UInt16 signatureLen)
{
 OSStatus        err;
 ...

 if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
  goto fail;
 if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
  goto fail;
  goto fail;
 if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
  goto fail;
  ...

fail:
 SSLFreeBuffer(&signedHashes);
 SSLFreeBuffer(&hashCtx);
 return err;
}
Rewritten so that the relationship between the cascaded IFs is visible and automatically checked. Minor liberty in capitalizing the ELSEs.
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) 
  goto fail;
ELSE if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
  goto fail;
  goto fail;
ELSE if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
  goto fail;
  ...
ELSE
  ...
  return 0;
Plus, I am sure that somebody has pointed out that an assert would also have caught the error.
fail:
  assert(err != 0 );
  SSLFreeBuffer(&signedHashes);
  SSLFreeBuffer(&hashCtx);
  return err;

Wednesday, September 18, 2013

Email flow with rules and labels

Email arrives.

A rule determines that it is low priority.  So I want it to be labelled Inbox/Low_Priority.

I.e. I do NOT want to see it in my normal Inbox.  Aka my priority Inbox.

But I *do* want to see it as a subfolder of my Inbox.   So, here is an example of a case where I do not want the browseable interface to the label graph to show all items with label - where the fact that it has a sublabel (of a particular type) implying that it should not be shown as the default query for Inbox.  But of course I might want to be able to see all items tagged Inbox, ewven though sublabels imply hiding.

Possibility: steal an idea from Bazaar DVCS:  Inbox/* => all items with label Inbox, but not with "masking" sublabels.   Whereas Inbox/** => all labels tagged Inbox, even with masking sublabels.

Inbox|Some_Other_Label - independent, not really path oriented
Inbox/NonMaskingSubLabel
Inbox//MaskingSubLabel

I probably won't get around to processing such Inbox/LowPriority emails very often.  But when I do, and I handle them, I probably want to change the label from Inbox/LowPriority to straight LowPriority.

I.e. LowPriority is not just a sublabel.  It is actually an independent label. But the instance on a particular item may indicate the masking sublabel relationship to Inbox.

If something gets tagged Inbox/SubLabel initially, and then just becomes SubLabel, and then is moved back to Inbox, should it go back to being Inbox/Subel?  Or should it be Inbox|SubLabel?

If Inbox/SubLabel -> SubLabel -> Inbox/SubLabe, should this be

a) because it was originally Inbox/SubLabel - i.e. based on history of the labelling?

or

b) because SubLabel is marked as being in a possibly subservient relationship to Inbox?


Inbox is a special case.